Can I use template aliases as template template parameters?
template <template <typename...> class> struct foo {}; template <typename T> using simple_ptr = std::unique_ptr<T>; foo<std::unique_ptr> a; // this doesn't work, std::unique_ptr has two parameters foo<simple_ptr> b; // does this work?
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.)
For example, given a specialization Stack<int>, “int” is a template argument. Instantiation: This is when the compiler generates a regular class, method, or function by substituting each of the template's parameters with a concrete type.
8. Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.
In C++ this can be achieved using template parameters. 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.
Yes, it is apparently allowed. According to the latest draft of the upcoming standard I could find, it is stated that
A template-argument for a template template-parameter shall be the name of a class template or an alias template [...].
However, alias templates seems very seldomly supported at the moment, so you might have some trouble making it work with most compilers.
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