alpaka
Abstraction Library for Parallel Kernel Acceleration
IntegerSequence.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/meta/Set.hpp"
8 
9 #include <cstddef>
10 #include <type_traits>
11 #include <utility>
12 
13 namespace alpaka::meta
14 {
15  namespace detail
16  {
17  template<typename TDstType, typename TIntegerSequence>
19 
20  template<typename TDstType, typename T, T... Tvals>
21  struct ConvertIntegerSequence<TDstType, std::integer_sequence<T, Tvals...>>
22  {
23  using type = std::integer_sequence<TDstType, static_cast<TDstType>(Tvals)...>;
24  };
25  } // namespace detail
26 
27  template<typename TDstType, typename TIntegerSequence>
29 
30  namespace detail
31  {
32  template<bool TisSizeNegative, bool TbIsBegin, typename T, T Tbegin, typename TIntCon, typename TIntSeq>
34  {
35  static_assert(!TisSizeNegative, "MakeIntegerSequence<T, N> requires N to be non-negative.");
36  };
37 
38  template<typename T, T Tbegin, T... Tvals>
40  false,
41  true,
42  T,
43  Tbegin,
44  std::integral_constant<T, Tbegin>,
45  std::integer_sequence<T, Tvals...>>
46  {
47  using type = std::integer_sequence<T, Tvals...>;
48  };
49 
50  template<typename T, T Tbegin, T TIdx, T... Tvals>
52  false,
53  false,
54  T,
55  Tbegin,
56  std::integral_constant<T, TIdx>,
57  std::integer_sequence<T, Tvals...>>
58  {
59  using type = typename MakeIntegerSequenceHelper<
60  false,
61  TIdx == (Tbegin + 1),
62  T,
63  Tbegin,
64  std::integral_constant<T, TIdx - 1>,
65  std::integer_sequence<T, TIdx - 1, Tvals...>>::type;
66  };
67  } // namespace detail
68 
69  template<typename T, T Tbegin, T Tsize>
71  (Tsize < 0),
72  (Tsize == 0),
73  T,
74  Tbegin,
75  std::integral_constant<T, Tbegin + Tsize>,
76  std::integer_sequence<T>>::type;
77 
78  //! Checks if the integral values are unique.
79  template<typename T, T... Tvals>
81  {
83  };
84 
85  //! Checks if the values in the index sequence are unique.
86  template<typename TIntegerSequence>
88 
89  //! Checks if the values in the index sequence are unique.
90  template<typename T, T... Tvals>
91  struct IntegerSequenceValuesUnique<std::integer_sequence<T, Tvals...>>
92  {
93  static constexpr bool value = IntegralValuesUnique<T, Tvals...>::value;
94  };
95 
96  //! Checks if the integral values are within the given range.
97  template<typename T, T Tmin, T Tmax, T... Tvals>
99 
100  //! Checks if the integral values are within the given range.
101  template<typename T, T Tmin, T Tmax>
102  struct IntegralValuesInRange<T, Tmin, Tmax>
103  {
104  static constexpr bool value = true;
105  };
106 
107  //! Checks if the integral values are within the given range.
108  template<typename T, T Tmin, T Tmax, T I, T... Tvals>
109  struct IntegralValuesInRange<T, Tmin, Tmax, I, Tvals...>
110  {
111  static constexpr bool value
112  = (I >= Tmin) && (I <= Tmax) && IntegralValuesInRange<T, Tmin, Tmax, Tvals...>::value;
113  };
114 
115  //! Checks if the values in the index sequence are within the given range.
116  template<typename TIntegerSequence, typename T, T Tmin, T Tmax>
118 
119  //! Checks if the values in the index sequence are within the given range.
120  template<typename T, T... Tvals, T Tmin, T Tmax>
121  struct IntegerSequenceValuesInRange<std::integer_sequence<T, Tvals...>, T, Tmin, Tmax>
122  {
123  static constexpr bool value = IntegralValuesInRange<T, Tmin, Tmax, Tvals...>::value;
124  };
125 } // namespace alpaka::meta
typename detail::ConvertIntegerSequence< TDstType, TIntegerSequence >::type ConvertIntegerSequence
typename detail::MakeIntegerSequenceHelper<(Tsize< 0),(Tsize==0), T, Tbegin, std::integral_constant< T, Tbegin+Tsize >, std::integer_sequence< T > >::type MakeIntegerSequenceOffset
Checks if the values in the index sequence are within the given range.
Checks if the values in the index sequence are unique.
Checks if the integral values are within the given range.
Checks if the integral values are unique.
std::integer_sequence< TDstType, static_cast< TDstType >(Tvals)... > type
typename MakeIntegerSequenceHelper< false, TIdx==(Tbegin+1), T, Tbegin, std::integral_constant< T, TIdx - 1 >, std::integer_sequence< T, TIdx - 1, Tvals... > >::type type