class Blob { std::vector<std::string> _v; public: template<typename... Args> Blob(Args&&... args) : _v(std::forward<Args>(args)...) { } }; int main(void) { const char * shapes[3] = { "Circle", "Triangle", "Square" }; Blob b1(5, "C++ Truths"); Blob b2(shapes, shapes+3); }

class Blob { std::vector<std::string> _v; std::list<double> _l; public: template<typename... Args> Blob(Args&&... args) : _v(???) _l(???) { } }; int main(void) { Blob b3(5, 10, 10.0); // Three parameters and two constructors. How do we group? }

Blob b3(std::make_tuple(5), std::make_tuple(10, 99.99));

template<unsigned...> struct index_tuple{}; template<unsigned I, typename IndexTuple, typename... Types> struct make_indices_impl; template<unsigned I, unsigned... Indices, typename T, typename... Types> struct make_indices_impl<I, index_tuple<Indices...>, T, Types...> { typedef typename make_indices_impl<I + 1, index_tuple<Indices..., I>, Types...>::type type; }; template<unsigned I, unsigned... Indices> struct make_indices_impl<I, index_tuple<Indices...> > { typedef index_tuple<Indices...> type; }; template<typename... Types> struct make_indices : make_indices_impl<0, index_tuple<>, Types...> {};

template <unsigned... Indices, class... Args, class Ret> Ret forward_impl(index_tuple<Indices...>, std::tuple<Args...> tuple, Ret (*fptr) (Args...)) { return fptr(std::get<Indices>(tuple)...); } template<class... Args, class Ret> Ret forward(std::tuple<Args...> tuple, Ret (*fptr) (Args...)) { typedef typename make_indices<Args...>::type Indices; return forward_impl(Indices(), tuple, fptr); } int myfunc(int i, bool, double) { return 5 + i; } int main() { std::cout << forward(std::make_tuple(42, true, 1.2), myfunc) << std::endl; }

class Blob { std::vector<std::string> _v; std::list<double> _l; public: template <typename... Args1, typename... Args2> Blob(std::tuple<Args1...> tuple1, std::tuple<Args2...> tuple2) : Blob(tuple1, tuple2, typename make_indices<Args1...>::type(), typename make_indices<Args2...>::type()) {} private: template <typename... Args1, typename... Args2, unsigned... Indices1, unsigned... Indices2> Blob(std::tuple<Args1...> tuple1, std::tuple<Args2...> tuple2, index_tuple<Indices1...>, index_tuple<Indices2...>) : _v(std::forward<Args1>(std::get<Indices1>(tuple1))...), _l(std::forward<Args2>(std::get<Indices2>(tuple2))...) { } };

int main(void) { Blob b3(std::forward_as_tuple(5, "C++ Truths"), std::forward_as_tuple(10, 99.99)); // b3._v has 5 strings initialized to "C++ Truths" and // b3._l has 10 doubles initialized to 99.99 Blob b4(std::forward_as_tuple(5), std::forward_as_tuple(10, 99.99)); // b4._v has 5 empty strings and // b4._l has 10 doubles initialized to 99.99 Blob b5(std::forward_as_tuple(), std::forward_as_tuple(10, 99.99)); // b5._v is an empty vector // b5._l has 10 doubles initialized to 99.99 }

#include <utility> // ... template <typename... Args1, typename... Args2> Blob(std::piecewise_construct_t, std::tuple<Args1...> tuple1, std::tuple<Args2...> tuple2) : Blob(tuple1, tuple2, typename make_indices<Args1...>::type(), typename make_indices<Args2...>::type()) {} //... Blob b3(std::piecewise_construct, std::forward_as_tuple(5, "C++ Truths"), std::forward_as_tuple(10, 99.99));