If I have a template class:
template<typename Layout>
class LayoutHandler : Handler {
};
and I want to expose the parameter Layout to the user of the class. Then:
template<typename Layout>
class LayoutHandler : Handler {
public:
typedef Layout Layout; // using the same name
};
VS2012 can compile this code, and give the expected result. (I use std::is_same to check it.) Is this allowed in standard C++03 or C++11?
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.)
Non-type template parameters are one of the few places in C++ where a visible distinction is made between class types and others: integral types, enum types, pointer types, point- to-member types, reference types and std::nullptr_t can all be used as non-type template parameters, but class types cannot.
Template classes and functions can make use of another kind of template parameter known as a non-type parameter. 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.
8. Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.
It is not allowed in C++11.
A typedef
is a declaration. (see section 7.1.3)
A template
parameter can't be redeclared within its scope (including nested scopes). (see section 14.6.1.6)
C++11 draft standard n3242
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