我可以使用模板别名作为模板模板参数吗?

R. *_*des 37 c++ templates c++11 template-aliases

我可以使用模板别名作为模板模板参数吗?

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?
Run Code Online (Sandbox Code Playgroud)

Luc*_*lle 25

是的,显然是允许的.根据我能找到的即将出台的标准的最新草案,据说

模板template-parametertemplate-argument应该是类模板或别名模板的名称[...].

但是,目前似乎很少支持别名模板,因此您可能在使其适用于大多数编译器时遇到一些麻烦.