fork(10) download
  1. #include <vector>
  2. #include <tuple>
  3. #include <algorithm>
  4.  
  5. template<class... Ts>
  6. std::vector<std::tuple<Ts...>> zip(std::vector<Ts> const&... vs){
  7. auto lo = std::min({vs.size()...});
  8. std::vector<std::tuple<Ts...>> v;
  9. v.reserve(lo);
  10. for(unsigned i = 0; i < lo; ++i)
  11. v.emplace_back(vs[i]...);
  12. return v;
  13. }
  14.  
  15. #include <iostream>
  16.  
  17. int main(){
  18. std::vector<int> a{1,3,5}, b{2,4,6}, c{3,5,7};
  19. for(auto&& t : zip(a, b, c)){
  20. std::cout << std::get<0>(t) << ":" << std::get<1>(t) << ":" << std::get<2>(t) << "\n";
  21. }
  22. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
1:2:3
3:4:5
5:6:7