I need to forward the values of a tuple to a member initializer:
struct Struct {
Member1 member1;
Member2 member2;
template<typename Tuple1, typename Tuple2>
Struct( Tuple1&& tuple1, Tuple2&& tuple2 )
: member1(tuple1...), member2(tuple2...)
{}
};
The code above obviously isn't valid. How can I express it?
Member1
and Member2
have no default/copy/move constructor.
I know about std::apply
, as suggested in How do I expand a tuple into variadic template function's arguments?. I also know about std::make_from_tuple
. But I wouldn't know how to use any of these in a member initializer.
Any C++ standard is fine (preferably C++17, but C++20 would work as well).
To clarify, my real goal is to create a Struct
, passing it two sets of variadic arguments to perfect-forward them to initialize member1
and member2
. I thought that "grouping" the two sets into tuples could have been a good idea, since that's what std::map::emplace
does. Other approaches would work as well (e.g. passing a special object between the two sets of variadic arguments).