可变参数模板模板参数
以下代码无法使用 clang 3.0 进行编译,这是因为我做错了吗?因为它在 c++11 中不允许,或者因为它在 clang 中不支持?
template<int OFFSET>
struct A {
enum O { offset = OFFSET };
};
template < template <int T> class Head, typename... Tail>
struct C : public Head<1>, private C<Tail> { };
int main()
{
C< A, A > c1;
return 0;
}
编译器错误:
test3.cxx:99:42: error: template argument for template template parameter must be a class template or type alias template
struct C : public Head<1>, private C<Tail> { };
^
test3.cxx:103:15: error: use of class template A requires template arguments
C< A, A > c1;
^
test3.cxx:94:12: note: template is declared here
struct A {
^
2 errors generated.
The following code does not compiles using clang 3.0, is this because I have done it wrongly? Because it is not allowed in c++11 or because it is not supported in clang?
template<int OFFSET>
struct A {
enum O { offset = OFFSET };
};
template < template <int T> class Head, typename... Tail>
struct C : public Head<1>, private C<Tail> { };
int main()
{
C< A, A > c1;
return 0;
}
Compiler error:
test3.cxx:99:42: error: template argument for template template parameter must be a class template or type alias template
struct C : public Head<1>, private C<Tail> { };
^
test3.cxx:103:15: error: use of class template A requires template arguments
C< A, A > c1;
^
test3.cxx:94:12: note: template is declared here
struct A {
^
2 errors generated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
三个问题:
Tail
是模板的可变列表,而不是类型的列表。因此它应该是而不是
,并且您需要使用
private C
而不是private C
显式扩展参数包。当
Tail...
为空时,您需要实现基本情况:(这是使用 Clang 3.0 进行编译的)
现在的整段代码:
Three issues:
Tail
is to be a variadic list of templates, not of types. Hence it should beinstead of
and you need to explicitly expand the parameter pack with
private C<Tail...>
instead ofprivate C<Tail>
.And you'll need to implement the base case, for when
Tail...
is empty:(This is compiling for with Clang 3.0)
The entire piece of code now: