distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
ContiguousRange.hpp
Go to the documentation of this file.
1 
12 #ifndef ESTD_CONTIGUOUSRANGE_HPP_
13 #define ESTD_CONTIGUOUSRANGE_HPP_
14 
15 #include <array>
16 
17 namespace estd
18 {
19 
26 template<typename T>
28 {
29 public:
30 
32  using value_type = T;
33 
35  using pointer = value_type*;
36 
38  using const_pointer = const value_type*;
39 
42 
44  using const_reference = const value_type&;
45 
47  using iterator = value_type*;
48 
50  using const_iterator = const value_type*;
51 
53  using size_type = std::size_t;
54 
56  using difference_type = std::ptrdiff_t;
57 
59  using reverse_iterator = std::reverse_iterator<iterator>;
60 
62  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
63 
71  constexpr ContiguousRange(const iterator beginn, const iterator endd) noexcept :
72  begin_{beginn},
73  end_{endd}
74  {
75 
76  }
77 
82  constexpr ContiguousRange() noexcept :
83  ContiguousRange{nullptr, nullptr}
84  {
85 
86  }
87 
95  constexpr ContiguousRange(const iterator beginn, size_t sizee) noexcept :
96  begin_{beginn},
97  end_{beginn + sizee}
98  {
99 
100  }
101 
110  template<size_t N>
111  constexpr explicit ContiguousRange(T (& array)[N]) noexcept :
112  ContiguousRange{array, array + N}
113  {
114 
115  }
116 
125  template<size_t N>
126  constexpr explicit ContiguousRange(std::array<T, N>& array) noexcept :
127  ContiguousRange{array.begin(), array.end()}
128  {
129 
130  }
131 
140  template<size_t N>
141  constexpr explicit ContiguousRange(const std::array<typename std::remove_const<T>::type, N>& array) noexcept :
142  ContiguousRange{array.begin(), array.end()}
143  {
144 
145  }
146 
157  template<size_t N, typename TT = T, typename = typename std::enable_if<std::is_const<TT>::value == true>::type>
158  constexpr explicit ContiguousRange(const std::array<T, N>& array) noexcept :
159  ContiguousRange{array.begin(), array.end()}
160  {
161 
162  }
163 
170  constexpr explicit ContiguousRange(T& value) noexcept :
171  ContiguousRange{&value, &value + 1}
172  {
173 
174  }
175 
184  template<typename TT = T, typename = typename std::enable_if<std::is_const<TT>::value == true>::type>
185  constexpr explicit ContiguousRange(const ContiguousRange<typename std::remove_const<TT>::type>& other) noexcept :
186  ContiguousRange{other.begin(), other.end()}
187  {
188 
189  }
190 
199  reference operator[](const size_type i) const noexcept
200  {
201  return begin_[i];
202  }
203 
208  constexpr iterator begin() const noexcept
209  {
210  return begin_;
211  }
212 
217  constexpr const_iterator cbegin() const noexcept
218  {
219  return begin();
220  }
221 
226  constexpr const_iterator cend() const noexcept
227  {
228  return end();
229  }
230 
235  constexpr const_reverse_iterator crbegin() const noexcept
236  {
237  return rbegin();
238  }
239 
245  constexpr const_reverse_iterator crend() const noexcept
246  {
247  return rend();
248  }
249 
254  constexpr iterator end() const noexcept
255  {
256  return end_;
257  }
258 
263  constexpr reverse_iterator rbegin() const noexcept
264  {
265  return reverse_iterator{end()};
266  }
267 
273  constexpr reverse_iterator rend() const noexcept
274  {
275  return reverse_iterator{begin()};
276  }
277 
282  constexpr size_type size() const noexcept
283  {
284  return end_ - begin_;
285  }
286 
287 private:
288 
291 
294 };
295 
296 } // namespace estd
297 
298 #endif // ESTD_CONTIGUOUSRANGE_HPP_
Collection of useful templates.
Definition: DmaChannel.hpp:121
constexpr ContiguousRange() noexcept
Empty ContiguousRange's constructor.
Definition: ContiguousRange.hpp:82
iterator begin_
iterator to first element in the range
Definition: ContiguousRange.hpp:290
value_type * iterator
iterator type
Definition: ContiguousRange.hpp:47
constexpr ContiguousRange(T &value) noexcept
ContiguousRange's constructor using single value.
Definition: ContiguousRange.hpp:170
constexpr ContiguousRange(const std::array< typename std::remove_const< T >::type, N > &array) noexcept
ContiguousRange's constructor using const std::array.
Definition: ContiguousRange.hpp:141
std::size_t size_type
size_type type
Definition: ContiguousRange.hpp:53
const value_type & const_reference
const_reference type
Definition: ContiguousRange.hpp:44
ContiguousRange template class is a pair of iterators to contiguous sequence of elements in memory.
Definition: ContiguousRange.hpp:27
constexpr ContiguousRange(const ContiguousRange< typename std::remove_const< TT >::type > &other) noexcept
ContiguousRange's converting constructor.
Definition: ContiguousRange.hpp:185
iterator end_
iterator to "one past the last" element in the range
Definition: ContiguousRange.hpp:293
std::reverse_iterator< iterator > reverse_iterator
reverse_iterator type
Definition: ContiguousRange.hpp:59
const value_type * const_iterator
const_iterator type
Definition: ContiguousRange.hpp:50
constexpr const_iterator cend() const noexcept
Definition: ContiguousRange.hpp:226
std::reverse_iterator< const_iterator > const_reverse_iterator
const_reverse_iterator type
Definition: ContiguousRange.hpp:62
constexpr reverse_iterator rbegin() const noexcept
Definition: ContiguousRange.hpp:263
constexpr reverse_iterator rend() const noexcept
Definition: ContiguousRange.hpp:273
constexpr ContiguousRange(const std::array< T, N > &array) noexcept
ContiguousRange's constructor using const std::array with const type.
Definition: ContiguousRange.hpp:158
constexpr const_reverse_iterator crend() const noexcept
Definition: ContiguousRange.hpp:245
constexpr ContiguousRange(T(&array)[N]) noexcept
ContiguousRange's constructor using C-style array.
Definition: ContiguousRange.hpp:111
constexpr ContiguousRange(std::array< T, N > &array) noexcept
ContiguousRange's constructor using std::array.
Definition: ContiguousRange.hpp:126
value_type * pointer
pointer type
Definition: ContiguousRange.hpp:35
reference operator[](const size_type i) const noexcept
ContiguousRange's subscript operator.
Definition: ContiguousRange.hpp:199
T value_type
value_type type
Definition: ContiguousRange.hpp:32
constexpr ContiguousRange(const iterator beginn, const iterator endd) noexcept
ContiguousRange's constructor.
Definition: ContiguousRange.hpp:71
constexpr size_type size() const noexcept
Definition: ContiguousRange.hpp:282
constexpr ContiguousRange(const iterator beginn, size_t sizee) noexcept
ContiguousRange's constructor using iterator and size.
Definition: ContiguousRange.hpp:95
value_type & reference
reference type
Definition: ContiguousRange.hpp:41
constexpr const_reverse_iterator crbegin() const noexcept
Definition: ContiguousRange.hpp:235
const value_type * const_pointer
const_pointer type
Definition: ContiguousRange.hpp:38
constexpr iterator begin() const noexcept
Definition: ContiguousRange.hpp:208
constexpr const_iterator cbegin() const noexcept
Definition: ContiguousRange.hpp:217
constexpr iterator end() const noexcept
Definition: ContiguousRange.hpp:254
std::ptrdiff_t difference_type
difference_type type
Definition: ContiguousRange.hpp:56