[英]std::tuple as class member
How to create an object with member of type std::tuple
? 如何使用
std::tuple
类型的成员创建对象?
I tried to compile this code. 我试着编译这段代码。
6 template <class ... T>
7 class Iterator
8 {
9 public:
10 Iterator(T ... args)
11 : tuple_(std::make_tuple(args))
12 {
13 }
14
15 private:
16 std::tuple<T ...> tuple_;
17 };
But it is unable to compile with the following error. 但它无法使用以下错误进行编译。
variadic.cpp: In constructor ‘Iterator<T>::Iterator(T ...)’:
variadic.cpp:11:33: error: parameter packs not expanded with ‘...’:
variadic.cpp:11:33: note: ‘args’
What is wrong with the code? 代码有什么问题?
args
is variadic, so you have to expand it with ...
: args
是可变的,所以你必须用...
扩展它:
: tuple_(std::make_tuple(args...))
// ^^^
And you don't need make_tuple
for this: 而你不需要
make_tuple
:
: tuple_(args...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.