模板参数的模板参数必须是类模板或类型别名模板

时间:2021-12-15 16:33:35
template<typename... TArgs> struct List { };
template<template<typename...> class> struct ListHelper;
template<typename T, typename... TArgs> struct ListHelper<List<T, TArgs...>> { };
                                                          ^
   /*Error: Template argument for template template parameter 
             must be a class template or type alias template*/

What's wrong? I'm using clang++ SVN.

怎么了?我用铿锵声+ + SVN。

2 个解决方案

#1


12  

You have a template template parameter. You must pass a template as its argument. You instead pass a template instantiation as its argument - which is a concrete class, not a template (all its parameters are bound).

您有一个模板模板参数。您必须传递一个模板作为它的参数。相反,您将模板实例化传递为它的参数——它是一个具体的类,而不是一个模板(它的所有参数都是绑定的)。

Consider:

考虑:

template <template<typename> typename X>
class WantsTemplate {};

template <typename>
class ATemplate {};

WantsTemplate<ATemplate> wt1;  // OK
WantsTemplate<ATemplate<int> > wt2;  // not OK

#2


1  

A template template parameter expects the template, not an instantiation of it. This:

模板模板参数期望模板,而不是实例化。这样的:

template<typename T, typename... TArgs> struct ListHelper<List> { };
//                               only the template itself ^^^^

If you want to pass List<T,TArgs...>, which is a class, you'd need

如果你想通过列表 是一个类,你需要它 ,targs…>

template<typename T> struct ListHelper;

#1


12  

You have a template template parameter. You must pass a template as its argument. You instead pass a template instantiation as its argument - which is a concrete class, not a template (all its parameters are bound).

您有一个模板模板参数。您必须传递一个模板作为它的参数。相反,您将模板实例化传递为它的参数——它是一个具体的类,而不是一个模板(它的所有参数都是绑定的)。

Consider:

考虑:

template <template<typename> typename X>
class WantsTemplate {};

template <typename>
class ATemplate {};

WantsTemplate<ATemplate> wt1;  // OK
WantsTemplate<ATemplate<int> > wt2;  // not OK

#2


1  

A template template parameter expects the template, not an instantiation of it. This:

模板模板参数期望模板,而不是实例化。这样的:

template<typename T, typename... TArgs> struct ListHelper<List> { };
//                               only the template itself ^^^^

If you want to pass List<T,TArgs...>, which is a class, you'd need

如果你想通过列表 是一个类,你需要它 ,targs…>

template<typename T> struct ListHelper;