Reputation:
How to create an object with member of type 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?
Upvotes: 4
Views: 2083
Reputation: 96845
args
is variadic, so you have to expand it with ...
:
: tuple_(std::make_tuple(args...))
// ^^^
And you don't need make_tuple
for this:
: tuple_(args...)
Upvotes: 14