C++模板类型包装元组专业
试图实现元组类型时,我会遇到一个空元组。
这是我使用的类型结构:
template <class T, class... Ts>
struct Tuple : public Tuple<Ts...> {};
template <class T>
struct Tuple {};
一旦我尝试添加一个无类型编译器的过载,编译器就会抱怨:类模板'tuple''
的模板参数太少:
template <> struct Tuple<> {};
我想是因为这是因为首先以至少一种提供的类型声明了元组类型,并且编译器无法用不同的模板参数超载相同的类型,但是我想知道我如何在不完全重组我的代码的情况下解决此问题。
我的第一个想法是定义元组,例如template&lt; class ... ts&gt;结构元组{};
首先,而不是添加其他过载,但是编译器比向大量模板参数投诉。
When trying to implement a tuple type i run into the problem an empty tuple.
This is the type structure i used:
template <class T, class... Ts>
struct Tuple : public Tuple<Ts...> {};
template <class T>
struct Tuple {};
As soon as i try to add an overload for no type the compiler complains: Too few template arguments for class template 'Tuple'
:
template <> struct Tuple<> {};
I guess it's because the Tuple type was declared with at least one provided type at first and the compiler can't overload the same type with a different set of template parameters, but i wonder how i could solve this problem without completely restructuring my code.
My first idea was to define the tuple like template <class... Ts> struct Tuple {};
first and than add the other overloads, but the compiler than complains for to much template arguments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的模板期望至少一个参数。您可以这样更改它以允许零或更多:
Your template expects at least one parameter. You can change it like this to allow zero or more: