Is there any update in the upcoming C++0x standard on named parameters in templates and/or functions? For example, I would like to be able to write the following:
having defined previously:
template<class T = int,class Policy_1, class Policy_2>
class X
{
};
then in main:
X<Policy_2: NoReturn> x;
this same with functions; having:
void f(int arg_1 = 0, int arg_2 = 1, int arg_3 = 2)
{
}
then in main:
f(arg_3: 55);
In UML models, template parameters are formal parameters that once bound to actual values, called template arguments, make templates usable model elements. You can use template parameters to create general definitions of particular types of template.
An identifier that names a non-type template parameter of class type T denotes a static storage duration object of type const T, called a template parameter object, whose value is that of the corresponding template argument after it has been converted to the type of the template parameter.
Template parameters may have default arguments. The set of default template arguments accumulates over all declarations of a given template.
Explanation of the code: In the above program, the Test constructor has two arguments of generic type. The type of arguments is mentioned inside angle brackets < > while creating objects.
For functions you can use the Named Parameters Idiom (in both C++98 and C++0x).
See C++ FAQ item 10.20 What is the "Named Parameter Idiom"?.
For template arguments I think you can use the idea of wrapping, using "type carrier" types that by their type encode which template argument they are. It gets complex. You might check out the Boost Parameters library for ideas, but essentially, for template arguments I do not think it's worth spending time on (not to mention actually using) -- it's academic.
Cheers & hth.,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With