Is this legal C++?
template <typename T, template <typename T> class>
struct S { };
Clang (3.7.1) rejects it, complaining the second T
shadows the first T
. GCC seems not to care about it and I think that's reasonable. I think it is only the number of parameters that matters in a template template parameter.
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.
A template argument for a template template parameter is the name of a class template. When the compiler tries to find a template to match the template template argument, it only considers primary class templates. (A primary template is the template that is being specialized.)
A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.
A template non-type parameter is a template parameter where the type of the parameter is predefined and is substituted for a constexpr value passed in as an argument. A non-type parameter can be any of the following types: An integral type. An enumeration type.
No. [temp.local]/6:
A template-parameter shall not be redeclared within its scope (including nested scopes).
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