First of all, our first step is, of course, to unpack the tuple. Tuple provides a get function to get the nth element. For example:get<1> (Make_tuple (...)); To disassemble a tuple completely, it can be parsed by invoking the function multiple times, for example: Auto Tup = Make_tuple (...); Func (get<0> (tup),get<1> (tup),get<2> (tup) ......get<n> (Tup)); in fact, 0,1,... n This sequence we can construct a std::index_squence<0,1,2,..., n>, where n = std::tuple_size< decltype (tup) >::value- 1, then we pass template<size_t ... i,typename t> auto func (std::index_squence<i...>, t&& t) { Return funcc_ (get<i> (t) ...);} In this way, all the elements of a tuple can be unpacked. One of the std::index_squence<0,1,2,..., n> is obtained by std::make_index_sequence<n+1>. Now unpack the constructor for the class, if you have the following scenario: Auto Tup = Make_tuple (...); A (tup); we just need to define a few of the following constructors. struct a{//The first called constructor, where a index_squence is generated and the second constructor is called. Template<typename t> A (T T): A (std::make_index_squence< std::tuple_size<t>::value >,t) {}// Here is the second constructor, which will unpack the tuple and then call the third constructor template<size_t ... i,typename t> a (Std::index_squence<i...>,t t ): A (get<i> (t) ...) {}//The third constructor, which is the direct use of a normalThe constructor for the parameter. A (...) {}}
A tuple is unpacked to the constructor of a class