Advertisement
Anna_Khashper

Untitled

Oct 16th, 2020 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. // Определение списка целых чисел времени компиляции IntList
  2. template <int ... Ints>
  3. struct IntList;
  4.  
  5. template <int H, int ... I>
  6. struct IntList <H, I...>
  7. {
  8.   static int const Head = H;
  9.   using Tail = IntList<I...>;
  10. };
  11.  
  12. template <>
  13. struct IntList <> {};
  14.  
  15. template <typename IL>
  16. struct IntLength
  17. {
  18.   static int const value = 1 + IntLength <typename IL::Tail>::value;
  19. };
  20.  
  21. template <>
  22. struct IntLength <IntList<>>
  23. {
  24.   static int const value = 0;
  25. };
  26.  
  27. // добавление элемента в начало списка
  28.  
  29. template<int H, typename IL>
  30. struct IntCons;
  31.  
  32. template<int H, int... Ints>
  33. struct IntCons<H, IntList<Ints...>>
  34. {
  35.   using type = IntList<H, Ints...>;
  36. };
  37.  
  38. // добавление элемента в конец списка
  39. template<typename IL, int N>
  40. struct IntAdd;
  41.  
  42. template<int... Ints, int N>
  43. struct IntAdd<IntList<Ints...>, N>
  44. {
  45.   using type = IntList<Ints..., N>;
  46. };
  47.  
  48. template <int N, typename IL = IntList<>>
  49. struct Generate;
  50.  
  51. template <int N, int... Ints>
  52. struct Generate <N, IntList<Ints...>>
  53. {
  54.   using type = typename IntAdd<typename Generate<N - 1, IntList<>>::type, N - 1>::type;
  55. };
  56.  
  57. template<>
  58. struct Generate<0>
  59. {
  60.   static const int length = 0;
  61.   using type = IntList<>;
  62. };
  63.  
  64. template<typename IL1, typename IL2>
  65. struct Zip;
  66.  
  67. template<typename... Ints1, typename... Ints2>
  68. struct Zip<IntList<Ints1...>, IntList<Ints2...>>
  69. {
  70.   using type = IntList<Ints1..., Ints2...>;
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement