Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use template aliases as template template parameters?

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? 
like image 993
R. Martinho Fernandes Avatar asked Sep 06 '11 12:09

R. Martinho Fernandes


People also ask

Can a template be a 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.)

Which is a correct example of template parameters?

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.

Why do we use :: template template parameter?

8. Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.

What can the template parameter in C++ template definition be?

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.


1 Answers

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.

like image 59
Luc Touraille Avatar answered Sep 28 '22 20:09

Luc Touraille