Learn How To Use C++ Variadic Templates For Windows Development With C++Builder
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: template class VariadicTemplate {}; templatetypename… Arguments> class VariadicTemplate {}; Any of the following ways to create an instance of this class template is valid: VariadicTemplate instance; VariadicTemplate instance; VariadicTemplate, std::string, std::string, std::vector> instance; VariadicTemplatedouble, float> instance; VariadicTemplatebool, unsigned short int, long> instance; VariadicTemplatechar, std::vectorint>, std::string, std::string, std::vectorlong long>> instance; Here’s a function template: template void SampleFunction(Arguments… parameters) {}; 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, SampleFunction(16, 24); SampleFunctionint, int>(16, 24); an equivalent function template would be like this: template void SampleFunction(T param1, U param2){}; templatetypename T, typename U> void SampleFunction(T param1, U param2){}; Head over and find out more about C++ variadic templates in the Embarcadero DocWiki!
