distortos  v0.5.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 
153  constexpr explicit ContiguousRange(T& value) noexcept :
154  ContiguousRange{&value, &value + 1}
155  {
156 
157  }
158 
167  template<typename TT = T, typename = typename std::enable_if<std::is_const<TT>::value == true>::type>
168  constexpr explicit ContiguousRange(const ContiguousRange<typename std::remove_const<TT>::type>& other) noexcept :
169  ContiguousRange{other.begin(), other.end()}
170  {
171 
172  }
173 
182  reference operator[](const size_type i) const noexcept
183  {
184  return begin_[i];
185  }
186 
191  constexpr iterator begin() const noexcept
192  {
193  return begin_;
194  }
195 
200  constexpr const_iterator cbegin() const noexcept
201  {
202  return begin();
203  }
204 
209  constexpr const_iterator cend() const noexcept
210  {
211  return end();
212  }
213 
218  constexpr const_reverse_iterator crbegin() const noexcept
219  {
220  return rbegin();
221  }
222 
228  constexpr const_reverse_iterator crend() const noexcept
229  {
230  return rend();
231  }
232 
237  constexpr iterator end() const noexcept
238  {
239  return end_;
240  }
241 
246  constexpr reverse_iterator rbegin() const noexcept
247  {
248  return reverse_iterator{end()};
249  }
250 
256  constexpr reverse_iterator rend() const noexcept
257  {
258  return reverse_iterator{begin()};
259  }
260 
265  constexpr size_type size() const noexcept
266  {
267  return end_ - begin_;
268  }
269 
270 private:
271 
274 
277 };
278 
279 } // namespace estd
280 
281 #endif // ESTD_CONTIGUOUSRANGE_HPP_
Collection of useful templates.
constexpr ContiguousRange() noexcept
Empty ContiguousRange&#39;s constructor.
Definition: ContiguousRange.hpp:82
iterator begin_
iterator to first element in the range
Definition: ContiguousRange.hpp:273
value_type * iterator
iterator type
Definition: ContiguousRange.hpp:47
constexpr ContiguousRange(T &value) noexcept
ContiguousRange&#39;s constructor using single value.
Definition: ContiguousRange.hpp:153
constexpr ContiguousRange(const std::array< typename std::remove_const< T >::type, N > &array) noexcept
ContiguousRange&#39;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&#39;s converting constructor.
Definition: ContiguousRange.hpp:168
iterator end_
iterator to "one past the last" element in the range
Definition: ContiguousRange.hpp:276
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:209
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:246
constexpr reverse_iterator rend() const noexcept
Definition: ContiguousRange.hpp:256
constexpr const_reverse_iterator crend() const noexcept
Definition: ContiguousRange.hpp:228
constexpr ContiguousRange(T(&array)[N]) noexcept
ContiguousRange&#39;s constructor using C-style array.
Definition: ContiguousRange.hpp:111
constexpr ContiguousRange(std::array< T, N > &array) noexcept
ContiguousRange&#39;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&#39;s subscript operator.
Definition: ContiguousRange.hpp:182
T value_type
value_type type
Definition: ContiguousRange.hpp:32
constexpr ContiguousRange(const iterator beginn, const iterator endd) noexcept
ContiguousRange&#39;s constructor.
Definition: ContiguousRange.hpp:71
constexpr size_type size() const noexcept
Definition: ContiguousRange.hpp:265
constexpr ContiguousRange(const iterator beginn, size_t sizee) noexcept
ContiguousRange&#39;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:218
const value_type * const_pointer
const_pointer type
Definition: ContiguousRange.hpp:38
constexpr iterator begin() const noexcept
Definition: ContiguousRange.hpp:191
constexpr const_iterator cbegin() const noexcept
Definition: ContiguousRange.hpp:200
constexpr iterator end() const noexcept
Definition: ContiguousRange.hpp:237
std::ptrdiff_t difference_type
difference_type type
Definition: ContiguousRange.hpp:56