I would do it like this:
template<typename... Ts, size_t... is> auto unzip_impl(list<tuple<Ts...>> const& l, std::index_sequence<is...>) { tuple<list<Ts>...> ret; for(auto const& el : l) { std::initializer_list<int> { (std::get<is>(ret).push_back(std::get<is>(el)), 0)... }; } return ret; } template <class... Ts> auto unzip(const list<tuple<Ts...>> & l) { return unzip_impl(l, std::index_sequence_for<Ts...>{}); }
live demonstration
also, more C ++ 17th version with fold expressions:
template<typename... Ts, size_t... is> auto unzip_impl(list<tuple<Ts...>> const& l, std::index_sequence<is...>) { tuple<list<Ts>...> ret; for(auto const& el : l) { (std::get<is>(ret).push_back(std::get<is>(el)),...); } return ret; }
live demonstration
krzaq source share