Template template typename?
When using template template syntax as in template <template <typename> class T>, it is required to use the keyword class, as using typename gives an error along the lines of:
error: template template parameter requires 'class' after the parameter list
Everywhere else the keywords typename and class are interchangeable in the basic case of declaring a template parameter.
You could argue that the requirement when using template template is a hint that you are expected to pass a class type, but this is not always the case (especially not after C++11 introduced templated type aliases).
template <template <typename> class T> // 'class' keyword required.
struct Foo {
using type = T<int>;
};
template <typename T>
using type = T (*)();
using func_ptr_t = Foo<type>::type;
What is the reasoning behind this?
- Is there any specific reason as to why
typenameis not allowed in template template declarations? - Does the C++ standard say anything about this?
typenameright now. - chris