Variable parameter template usage

Source: Internet
Author: User
Variable parameter templates
Variable-parameter templates to create template functions and template classes that can accept variable quantities of parameters
This program uses template functions to instantiate the basic usage of variable parameter templates
#include <iostream>
using namespace Std;
void One () {}//requires a non-parametric overloaded version when the last parameter is passed


Template <typename t>//When the last argument is left, the compiler takes precedence over the template so that the last output has no comma behind it.
void One (T v)
{
cout << v << Endl;
}


//... As a meta operator
F is a template parameter package, F is a function parameter package, T is matched with a type, F differs from T in that F matches any number of types
The key point is that the template parameter package F is matched to the function parameter package F, both in type and quantity.
Template <typename T, TypeName ... F>
void One (T V, f ... f)//each time a pass is taken out of all parameters to give V, so that you can recursively complete all the arguments
{
cout << v << ",";
One (f ...); The meta-operator ... On the right side of F, you can expand the parameter pack and expand a series of parameters passed to F
}


int main ()
{
One ("ASD", 1,2,3,4); This series of parameters is passed to the template function package f,f and then the parameter packet is passed to the function parameter package F


return 0;
}

Variable parameter template usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.