Skip to content

Instantly share code, notes, and snippets.

@nico159
Last active October 7, 2015 22:25
Show Gist options
  • Save nico159/1b121265e81b822ec41e to your computer and use it in GitHub Desktop.
Save nico159/1b121265e81b822ec41e to your computer and use it in GitHub Desktop.
#include <iostream>
#include <array>
#include <tuple>
template<size_t N, typename...T, template<typename, size_t = N> typename...Ts>
constexpr auto zip(Ts<T> const&...args) {
using Tp = std::tuple<T...>;
std::array<Tp, N> result;
for(size_t i = 0; i < result.size(); i++) {
result[i] = std::make_tuple(args[i]...);
}
return result;
}
int main(int argc, char **argv) {
std::array<int, 3> x1 { 1, 2, 3 };
std::array<int, 3> x2 { 0, 0, 0 };
std::array<float, 3> f1 { 1.1, 2.2, 3.3 };
std::cout << std::get<2>(zip(x1, x2, f1)[0]) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment