distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
IntegerSequence.hpp
Go to the documentation of this file.
1 
12 #ifndef ESTD_INTEGERSEQUENCE_HPP_
13 #define ESTD_INTEGERSEQUENCE_HPP_
14 
15 #include <type_traits>
16 
17 namespace estd
18 {
19 
29 template<typename T, T... Integers>
31 {
32 public:
33 
35  using value_type = T;
36 
41  constexpr static std::size_t size() noexcept
42  {
43  return sizeof...(Integers);
44  };
45 };
46 
55 template<std::size_t... Indexes>
56 using IndexSequence = IntegerSequence<std::size_t, Indexes...>;
57 
58 namespace internal
59 {
60 
68 template<typename T, T... Integers>
69 struct TypedSequence : IntegerSequence<T, Integers...>
70 {
72  using base = IntegerSequence<T, Integers...>;
73 
76 };
77 
84 template<typename Sequence>
86 
96 template<typename T, T... Integers>
97 struct DoubledIntegerSequence<TypedSequence<T, Integers...>>
98 {
101  using type = TypedSequence<T, Integers..., (sizeof...(Integers) + Integers)...>;
102 };
103 
111 template<bool Extend, typename Sequence>
113 {
115  using type = Sequence;
116 };
117 
127 template<typename T, T... Integers>
128 struct ExtendedIntegerSequence<true, TypedSequence<T, Integers...>>
129 {
132  using type = TypedSequence<T, Integers..., sizeof...(Integers)>;
133 };
134 
144 template<typename T, std::size_t N>
146  ExtendedIntegerSequence<N % 2 != 0,
147  typename DoubledIntegerSequence<typename MakeIntegerSequenceImplementation<T, N / 2>::type>::type>
148 {
149 
150 };
151 
160 template<typename T>
162 {
165 };
166 
176 template<typename T, T N>
177 struct MakeIntegerSequenceImplementationWrapper :
178  std::enable_if<N >= 0, MakeIntegerSequenceImplementation<T, static_cast<std::size_t>(N)>>::type
179 {
180  static_assert(N >= 0, "Number of elements in the sequence must be non-negative!");
181 };
182 
183 } // namespace internal
184 
198 template<typename T, T N>
199 using MakeIntegerSequence = typename internal::MakeIntegerSequenceImplementationWrapper<T, N>::type::base;
200 
211 template<std::size_t N>
213 
224 template<typename... T>
225 using IndexSequenceFor = MakeIndexSequence<sizeof...(T)>;
226 
227 } // namespace estd
228 
229 #endif // ESTD_INTEGERSEQUENCE_HPP_
Collection of useful templates.
Definition: DmaChannel.hpp:121
T value_type
integer type used for the elements of the sequence
Definition: IntegerSequence.hpp:35
MakeIntegerSequence< std::size_t, N > MakeIndexSequence
Generator of IndexSequence types.
Definition: IntegerSequence.hpp:212
DoubledIntegerSequence< MakeIntegerSequenceImplementation< T, N/2 >::type >::type type
same as Sequence
Definition: IntegerSequence.hpp:115
TypedSequence optionally extended by one element.
Definition: IntegerSequence.hpp:112
Compile-time sequence of integers.
Definition: IntegerSequence.hpp:30
TypedSequence with doubled number of elements.
Definition: IntegerSequence.hpp:85
static constexpr std::size_t size() noexcept
Definition: IntegerSequence.hpp:41
IntegerSequence with two internal type aliases.
Definition: IntegerSequence.hpp:69
Implementation of generator of IntegerSequence types.
Definition: IntegerSequence.hpp:145
typename internal::MakeIntegerSequenceImplementationWrapper< T, N >::type::base MakeIntegerSequence
Generator of IntegerSequence types.
Definition: IntegerSequence.hpp:199
MakeIndexSequence< sizeof...(T)> IndexSequenceFor
Generator of IndexSequence types.
Definition: IntegerSequence.hpp:225