
C++ Builder supports the Variadic templates. Variadic templates are template that take a variable number of arguments. Both the classes and functions can be variadic offered by C++11.
Templates have been a powerful feature in C++. Now, after the introduction of variadic templates, templates have proven themselves even more powerful. Variadic templates are a trustworthy solution to implement delegates and tuples.
Here’s a variadic class template:
1 2 |
template<typename... Arguments> class VariadicTemplate {}; |
Any of the following ways to create an instance of this class template is valid:
1 2 3 |
VariadicTemplate<double, float> instance; VariadicTemplate<bool, unsigned short int, long> instance; VariadicTemplate<char, std::vector<int>, std::string, std::string, std::vector<long long>> instance; |
Here’s a function template:
1 |
template void SampleFunction(Arguments… parameters) {}; |
The contents of the variadic template arguments are called parameter packs. These packs will then be unpacked inside the function parameters. For example, if you create a function call to the above variadic function template,
1 |
SampleFunction<int, int>(16, 24); |
an equivalent function template would be like this:
1 2 |
template<typename T, typename U> void SampleFunction(T param1, U param2){}; |
Head over and find out more about C++ variadic templates in the Embarcadero DocWiki!
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition