模板模板参数,为什么要强制类
Template template parameters, why is class forced?
如果我写的话,滴定的滴滴几乎全部说明;
vvvvv
template <template <typename, typename> class StdContainer, typename T>
class DerivedContainer: public StdContainer<T, std::allocator<T>>
{ /*...*/ };
为什么需要类关键字?那就是允许打字名称的时候,作为在所有其他模板上下文中的替换。歧义?另外标准状态的哪一部分?
注意;我不是从std容器中得出的,这只是一个例子。
在语法上要求 class
声明模板参数时的使用情况:
n3337,§14.1[temp.param]:
1模板参数的语法是:
template-parameter:
type-parameter
parameter-declaration
type-parameter:
class ...opt identifier opt
class identifier opt = type-id
typename ...opt identifier opt
typename identifier opt= type-id
template < template-parameter-list >
class
...opt identifier opt
template < template-parameter-list >
class
identifier opt = id-expression
我不知道这样做的确切原因。当您有一个简单的类型参数时,类型可以是从基本类型到用户声明的类,类模板的专业等。当它是模板模板参数时,它只能是类模板的名称。也许他们想强调这种差异 - 或者也许他们只是不愿意在语法中插入更多的线条并加剧了混乱。谁知道:)
class
具有两个含义:声明类(或类模板)或声明模板类型参数。
typename
可以代替第二个含义,但不能代替第一个含义。在模板模板参数中,您要声明类模板,因此您必须使用class
。
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 在C++中传递给函数时,为什么要指定数组大小作为参数
- 为什么 std::function 可以作为 std::not2 的参数?
- 当给定默认值时,为什么此模板参数推导失败
- 非类型指针和引用模板参数,以及在编译时如何/为什么解析它们.c++
- 为什么默认复制函数在按值发送参数时不调用?
- 为什么 std::绑定错误参数可以成功?
- 模板参数列表中的 false 在模板初始化期间计算为什么?
- 为什么我们不能重复使用具有不同模板参数的别名模板标识符?
- 为什么参数在构造 std::thread 时移动两次
- 为什么参数推断在此模板模板参数中不起作用
- 为什么参数接受"text"而不是字符串变量?
- 为什么参数可以在对象初始化时通过赋值运算符传递给构造函数?
- 在 temp.deduct.partial 中,为什么参数包的专用性较低?
- 为什么参数是 isdigit 整数?
- 为什么参数修饰符(即'const'或"易失性")不被视为函数类型或签名的一部分?
- 为什么参数匹配适用于非模板版本,但不适用于模板版本
- 为什么参数相关查找不适用于函数模板dynamic_pointer_cast
- 为什么参数与printf未定义行为中的转换说明符不匹配
- 为什么参数包扩展如此有限