You can easily do this in C ++ 14 using the usual helper function technique, which takes a sequence of indices as an added parameter:
template<std::size_t... I> auto elements_impl(int index, std::index_sequence<I...>) { return std::make_tuple( std::get<I>(vectors).at(index)... ); } auto elements(int index) { return elements_impl(index, std::index_sequence_for<Ts...>{}); }
It simply calls std::get<I> for the sequence number of each type, and then calls at on a vector at that location. I used at if vectors do not all hold an element at this index, but you can replace operator[] if your case does not require verification. Then all the results are sent to make_tuple to build the result set object.
source share