fork(1) download
  1. #include <algorithm>
  2. #include <cstdint>
  3. #include <iterator>
  4. #include <iostream>
  5. #include <tuple>
  6. #include <vector>
  7.  
  8. #include <iostream>
  9. #include <tuple>
  10. #include <utility>
  11.  
  12. template <typename Seq, typename T1, typename T2>
  13. struct cartesian_pairs_helper;
  14.  
  15. template <std::size_t...Is, typename T1, typename T2>
  16. struct cartesian_pairs_helper<std::index_sequence<Is...>, T1, T2>
  17. {
  18. static constexpr std::size_t size1 = std::tuple_size<T1>::value;
  19. using type = std::tuple<
  20. std::pair<
  21. std::tuple_element_t<Is / size1, T1>,
  22. std::tuple_element_t<Is % size1, T2>
  23. >...>;
  24. };
  25.  
  26. template <typename T1, typename T2>
  27. struct cartesian_pairs
  28. {
  29. using type = typename cartesian_pairs_helper<
  30. std::make_index_sequence<std::tuple_size<T1>::value
  31. * std::tuple_size<T2>::value>,
  32. T1, T2>::type;
  33. };
  34.  
  35. static_assert(std::is_same<
  36. std::tuple<
  37. std::pair<char, float>,
  38. std::pair<char, double>,
  39. std::pair<int, float>,
  40. std::pair<int, double>>,
  41. cartesian_pairs<std::tuple<char, int>, std::tuple<float, double>>::type
  42. >::value, "unexpected");
  43.  
  44. int main() {
  45. }
  46.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty