fork(7) download
  1. #include <type_traits> // std::is_same
  2.  
  3. #if 1 // Not in C++11 // make_index_sequence
  4. #include <cstdint>
  5.  
  6. template <std::size_t...> struct index_sequence {};
  7.  
  8. template <std::size_t N, std::size_t... Is>
  9. struct make_index_sequence : make_index_sequence<N - 1, N - 1, Is...> {};
  10.  
  11. template <std::size_t... Is>
  12. struct make_index_sequence<0u, Is...> : index_sequence<Is...> { using type = index_sequence<Is...>; };
  13.  
  14. #endif // make_index_sequence
  15.  
  16. namespace detail
  17. {
  18. template <typename Seq1, std::size_t Offset, typename Seq2> struct concat_seq;
  19.  
  20. template <std::size_t ... Is1, std::size_t Offset, std::size_t ... Is2>
  21. struct concat_seq<index_sequence<Is1...>, Offset, index_sequence<Is2...>>
  22. {
  23. using type = index_sequence<Is1..., (Offset + Is2)...>;
  24. };
  25.  
  26. }
  27.  
  28.  
  29. template <std::size_t N, std::size_t E>
  30. using gen_seq = typename detail::concat_seq<typename make_index_sequence<E>::type, E + 1, typename make_index_sequence<(N > E) ? (N - E - 1) : 0>::type>::type;
  31.  
  32. static_assert(std::is_same<index_sequence<0, 1, 3, 4>, gen_seq<5, 2>>::value, "");
  33. static_assert(std::is_same<index_sequence<1, 2>, gen_seq<3, 0>>::value, "");
  34. static_assert(std::is_same<index_sequence<0, 1, 2, 3>, gen_seq<4, 4>>::value, "");
  35.  
  36. int main() {}
  37.  
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty