Embedded Template Library 1.0
iterator.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2017 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_ITERATOR_INCLUDED
32#define ETL_ITERATOR_INCLUDED
33
34#include "platform.h"
35#include "type_traits.h"
36#include "utility.h"
37#include "private/addressof.h"
38
39#if ETL_USING_STL || defined(ETL_IN_UNIT_TEST)
40 #include <iterator>
41#endif
42
45
46namespace etl
47{
48 //***************************************************************************
49 // iterator tags
55 //struct contiguous_iterator_tag : public random_access_iterator_tag {};
56
57 //***************************************************************************
58 // iterator_traits
59
60 // For anything not a fundamental type.
61 template <typename TIterator, typename = typename etl::enable_if<!etl::is_fundamental<TIterator>::value, void>::type>
63 {
64 typedef typename TIterator::iterator_category iterator_category;
65 typedef typename TIterator::value_type value_type;
66 typedef typename TIterator::difference_type difference_type;
67 typedef typename TIterator::pointer pointer;
68 typedef typename TIterator::reference reference;
69 };
70
71 // For pointers.
72 template <typename T>
73 struct iterator_traits<T*, void>
74 {
75 typedef ETL_OR_STD::random_access_iterator_tag iterator_category;
76 typedef T value_type;
77 typedef ptrdiff_t difference_type;
78 typedef typename etl::remove_cv<T>::type* pointer;
79 typedef T& reference;
80 };
81
82 // For const pointers.
83 template <typename T>
84 struct iterator_traits<const T*, void>
85 {
86 typedef ETL_OR_STD::random_access_iterator_tag iterator_category;
87 typedef T value_type;
88 typedef ptrdiff_t difference_type;
89 typedef const typename etl::remove_cv<T>::type* pointer;
90 typedef const T& reference;
91 };
92
93 //***************************************************************************
94 // advance
95 template <typename TIterator, typename TDistance>
96 ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::output_iterator_tag)
97 {
98 while (n--)
99 {
100 ++itr;
101 }
102 }
103
104 template <typename TIterator, typename TDistance>
105 ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::forward_iterator_tag)
106 {
107 while (n--)
108 {
109 ++itr;
110 }
111 }
112
113 template <typename TIterator, typename TDistance>
114 ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::bidirectional_iterator_tag)
115 {
116 if (n > 0)
117 {
118 while (n--)
119 {
120 ++itr;
121 }
122 }
123 else
124 {
125 while (n++)
126 {
127 --itr;
128 }
129 }
130 }
131
132 template <typename TIterator, typename TDistance>
133 ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::random_access_iterator_tag)
134 {
135 itr += n;
136 }
137
138 template <typename TIterator, typename TDistance>
139 ETL_CONSTEXPR14 void advance(TIterator& itr, TDistance n)
140 {
141 typedef typename etl::iterator_traits<TIterator>::iterator_category tag;
142
143 advance_helper(itr, n, tag());
144 }
145
146 //***************************************************************************
147 // distance
148 template<typename TIterator>
149 ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::input_iterator_tag)
150 {
151 typename etl::iterator_traits<TIterator>::difference_type d = 0;
152
153 while (first != last)
154 {
155 ++d;
156 ++first;
157 }
158
159 return d;
160 }
161
162 template<typename TIterator>
163 ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::forward_iterator_tag)
164 {
165 typename etl::iterator_traits<TIterator>::difference_type d = 0;
166
167 while (first != last)
168 {
169 ++d;
170 ++first;
171 }
172
173 return d;
174 }
175
176 template<typename TIterator>
177 ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::bidirectional_iterator_tag)
178 {
179 typename etl::iterator_traits<TIterator>::difference_type d = 0;
180
181 while (first != last)
182 {
183 ++d;
184 ++first;
185 }
186
187 return d;
188 }
189
190 template<typename TIterator>
191 ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::random_access_iterator_tag)
192 {
193 return last - first;
194 }
195
196 template<typename TIterator>
197 ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance(TIterator first, TIterator last)
198 {
199 typedef typename etl::iterator_traits<TIterator>::iterator_category tag;
200
201 return distance_helper(first, last, tag());
202 }
203
204 //***************************************************************************
205 // Previous
206 template<typename TIterator>
207 ETL_CONSTEXPR14 TIterator prev(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
208 {
209 etl::advance(itr, -n);
210
211 return itr;
212 }
213
214 //***************************************************************************
215 // Next
216 template<typename TIterator>
217 ETL_CONSTEXPR14 TIterator next(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
218 {
219 etl::advance(itr, n);
220
221 return itr;
222 }
223
224 //***************************************************************************
225 // reverse_iterator
226 template <typename TIterator>
228 {
229 public:
230
231 typedef typename iterator_traits<TIterator>::iterator_category iterator_category;
232 typedef typename iterator_traits<TIterator>::value_type value_type;
233 typedef typename iterator_traits<TIterator>::difference_type difference_type;
234 typedef typename iterator_traits<TIterator>::pointer pointer;
235 typedef typename iterator_traits<TIterator>::reference reference;
236
237 typedef TIterator iterator_type;
238
239 ETL_CONSTEXPR14 reverse_iterator()
240 : current()
241 {
242 }
243
244 ETL_CONSTEXPR14 explicit reverse_iterator(TIterator itr)
245 : current(itr)
246 {
247 }
248
249 template <typename TOther>
250 ETL_CONSTEXPR14 reverse_iterator(const reverse_iterator<TOther>& other)
251 : current(other.base())
252 {
253 }
254
255 template<class TOther>
256 ETL_CONSTEXPR14 reverse_iterator& operator =(const reverse_iterator<TOther>& other)
257 {
258 current = other.base();
259
260 return (*this);
261 }
262
263 ETL_CONSTEXPR14 TIterator base() const
264 {
265 return current;
266 }
267
268 ETL_NODISCARD ETL_CONSTEXPR14 reference operator*() const
269 {
270 TIterator temp = current;
271
272 return *(--temp);
273 }
274
275 ETL_NODISCARD ETL_CONSTEXPR14 pointer operator->() const
276 {
277 TIterator temp = current;
278
279 return &(*--temp);
280 }
281
282 ETL_CONSTEXPR14 reverse_iterator& operator++()
283 {
284 --current;
285
286 return *this;
287 }
288
289 ETL_CONSTEXPR14 reverse_iterator operator++(int)
290 {
291 reverse_iterator temp = *this;
292 --current;
293
294 return temp;
295 }
296
297 ETL_CONSTEXPR14 reverse_iterator& operator--()
298 {
299 ++current;
300
301 return (*this);
302 }
303
304 ETL_CONSTEXPR14 reverse_iterator operator--(int)
305 {
306 reverse_iterator temp = *this;
307 ++current;
308
309 return temp;
310 }
311
312 ETL_CONSTEXPR14 reverse_iterator& operator+=(const difference_type offset)
313 {
314 current -= offset;
315
316 return (*this);
317 }
318
319 ETL_CONSTEXPR14 reverse_iterator& operator-=(const difference_type offset)
320 {
321 current += offset;
322
323 return (*this);
324 }
325
326 ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator operator+(const difference_type offset) const
327 {
328 return reverse_iterator(current - offset);
329 }
330
331 ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator operator-(const difference_type offset) const
332 {
333 return (reverse_iterator(current + offset));
334 }
335
336 ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](const difference_type offset) const
337 {
338 return (*(*this + offset));
339 }
340
341 protected:
342
343 TIterator current;
344 };
345
346 template <typename TIterator>
347 ETL_CONSTEXPR14 bool operator ==(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
348 {
349 return lhs.base() == rhs.base();
350 }
351
352 template <typename TIterator>
353 ETL_CONSTEXPR14 bool operator !=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
354 {
355 return !(lhs == rhs);
356 }
357
358 template <typename TIterator>
359 ETL_CONSTEXPR14 bool operator <(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
360 {
361 return rhs.base() < lhs.base();
362 }
363
364 template <typename TIterator>
365 ETL_CONSTEXPR14 bool operator >(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
366 {
367 return rhs < lhs;
368 }
369
370 template <typename TIterator>
371 ETL_CONSTEXPR14 bool operator <=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
372 {
373 return !(rhs < lhs);
374 }
375
376 template <typename TIterator>
377 ETL_CONSTEXPR14 bool operator >=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
378 {
379 return !(lhs < rhs);
380 }
381
382 template <typename TIterator>
383 ETL_CONSTEXPR14 typename reverse_iterator<TIterator>::difference_type operator -(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
384 {
385 return rhs.base() - lhs.base();
386 }
387
388 template <typename TIterator, class TDifference>
389 ETL_CONSTEXPR14 reverse_iterator<TIterator> operator +(TDifference n, const reverse_iterator<TIterator>& itr)
390 {
391 return itr.operator +(n);
392 }
393
394 //***************************************************************************
396 //***************************************************************************
397 template <typename TCategory, typename T, typename TDistance = ptrdiff_t, typename TPointer = T* , typename TReference = T& >
398 struct iterator
399 {
400 typedef T value_type;
401 typedef TDistance difference_type;
402 typedef TPointer pointer;
403 typedef TReference reference;
404 typedef TCategory iterator_category;
405 };
406
407#if ETL_USING_CPP11
408 //***************************************************************************
409 // move_iterator
410 template <typename TIterator>
411 class move_iterator
412 {
413 public:
414
415 typedef typename iterator_traits<TIterator>::iterator_category iterator_category;
416 typedef typename iterator_traits<TIterator>::value_type value_type;
417 typedef typename iterator_traits<TIterator>::difference_type difference_type;
418 typedef TIterator iterator_type;
419 typedef TIterator pointer;
420 typedef value_type&& reference;
421
422 move_iterator()
423 {
424 }
425
426 explicit move_iterator(TIterator itr)
427 : current(itr)
428 {
429 }
430
431 template <typename U>
432 move_iterator(const move_iterator<U>& itr)
433 : current(itr.base())
434 {
435 }
436
437 template <typename U>
438 move_iterator& operator =(const move_iterator<U>& itr)
439 {
440 current = itr.current;
441 return *this;
442 }
443
444 iterator_type base() const
445 {
446 return current;
447 }
448
449 pointer operator ->() const
450 {
451 return current;
452 }
453
454 reference operator *() const
455 {
456 return etl::move(*current);
457 }
458
459 move_iterator& operator++()
460 {
461 ++current;
462 return *this;
463 }
464
465 move_iterator& operator--()
466 {
467 --current;
468 return *this;
469 }
470
471 move_iterator operator++(int)
472 {
473 move_iterator temp = *this;
474 ++current;
475 return temp;
476 }
477
478 move_iterator operator--(int)
479 {
480 move_iterator temp = *this;
481 --current;
482 return temp;
483 }
484
485 move_iterator operator +(difference_type n) const
486 {
487 return move_iterator(current + n);
488 }
489
490 move_iterator operator -(difference_type n) const
491 {
492 return move_iterator(current - n);
493 }
494
495 move_iterator operator +=(difference_type n)
496 {
497 current += n;
498 return *this;
499 }
500
501 move_iterator operator -=(difference_type n)
502 {
503 current -= n;
504 return *this;
505 }
506
507 reference operator [](difference_type n) const
508 {
509 return etl::move(current[n]);
510 }
511
512 private:
513
514 TIterator current;
515 };
516
517 template <typename TIterator>
518 bool operator ==(const etl::move_iterator<TIterator>& lhs,
519 const etl::move_iterator<TIterator>& rhs)
520 {
521 return lhs.base() == rhs.base();
522 }
523
524 template <typename TIterator>
525 bool operator !=(const etl::move_iterator<TIterator>& lhs,
526 const etl::move_iterator<TIterator>& rhs)
527 {
528 return !(lhs == rhs);
529 }
530
531 template <typename TIterator>
532 bool operator <(const etl::move_iterator<TIterator>& lhs,
533 const etl::move_iterator<TIterator>& rhs)
534 {
535 return lhs.base() < rhs.base();
536 }
537
538 template <typename TIterator>
539 bool operator <=(const etl::move_iterator<TIterator>& lhs,
540 const etl::move_iterator<TIterator>& rhs)
541 {
542 return !(rhs < lhs);
543 }
544
545 template <typename TIterator>
546 bool operator >(const etl::move_iterator<TIterator>& lhs,
547 const etl::move_iterator<TIterator>& rhs)
548 {
549 return (rhs < lhs);
550 }
551
552 template <typename TIterator>
553 bool operator >=(const etl::move_iterator<TIterator>& lhs,
554 const etl::move_iterator<TIterator>& rhs)
555 {
556 return !(lhs < rhs);
557 }
558
559 template <typename TIterator>
560 move_iterator<TIterator> operator +(typename move_iterator<TIterator>::difference_type n,
561 const move_iterator<TIterator>& rhs)
562 {
563 return rhs + n;
564 }
565
566 template <typename TIterator1, typename TIterator2 >
567 auto operator -(const move_iterator<TIterator1>& lhs,
568 const move_iterator<TIterator2>& rhs) -> decltype(lhs.base() - rhs.base())
569 {
570 return lhs.base() - rhs.base();
571 }
572
573 template <typename TIterator>
574 etl::move_iterator<TIterator> make_move_iterator(TIterator itr)
575 {
576 return etl::move_iterator<TIterator>(itr);
577 }
578
579#endif //ETL_USING_CPP11
580
581 //***************************************************************************
582 // back_insert_iterator
583 //***************************************************************************
584
585 //***************************************************************************
592 //***************************************************************************
593 template <typename TContainer>
594 class back_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
595 {
596 public:
597
599 typedef TContainer container_type;
600
602 explicit ETL_CONSTEXPR14 back_insert_iterator(TContainer& c)
603 : container(etl::addressof(c))
604 {
605 }
606
607 //***************************************************************************
616 //***************************************************************************
617 ETL_CONSTEXPR14 back_insert_iterator& operator =(const typename TContainer::value_type& value)
618 {
619 container->push_back(value);
620
621 return (*this);
622 }
623
624#if ETL_USING_CPP11
625 //***************************************************************************
627 //***************************************************************************
628 ETL_CONSTEXPR14 back_insert_iterator& operator =(typename TContainer::value_type&& value)
629 {
630 container->push_back(etl::move(value));
631
632 return (*this);
633 }
634#endif // ETL_USING_CPP11
635
636 //***************************************************************************
639 //***************************************************************************
640 ETL_NODISCARD ETL_CONSTEXPR14 back_insert_iterator& operator *()
641 {
642 return (*this);
643 }
644
645 //***************************************************************************
648 //***************************************************************************
650 {
651 return (*this);
652 }
653
654 //***************************************************************************
657 //***************************************************************************
659 {
660 return (*this);
661 }
662
663 protected:
664
665 TContainer* container;
666 };
667
668 //***************************************************************************
678 //***************************************************************************
679 template <typename TContainer>
680 ETL_NODISCARD
681 ETL_CONSTEXPR14
683 {
685 }
686
687 //***************************************************************************
688 // front_insert_iterator
689 //***************************************************************************
690
691 //***************************************************************************
702 //***************************************************************************
703 template <typename TContainer>
704 class front_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
705 {
706 public:
707
709 typedef TContainer container_type;
710
711 //***************************************************************************
714 //***************************************************************************
715 explicit ETL_CONSTEXPR14 front_insert_iterator(TContainer& c)
716 : container(etl::addressof(c))
717 {
718 }
719
720 //***************************************************************************
730 //***************************************************************************
731 ETL_CONSTEXPR14 front_insert_iterator& operator =(const typename TContainer::value_type& value)
732 {
733 container->push_front(value);
734 return (*this);
735 }
736
737#if ETL_USING_CPP11
738 //***************************************************************************
740 //***************************************************************************
741 ETL_CONSTEXPR14 front_insert_iterator& operator =(typename TContainer::value_type&& value)
742 {
743 container->push_front(etl::move(value));
744 return (*this);
745 }
746#endif // ETL_USING_CPP11
747
748 //***************************************************************************
751 //***************************************************************************
752 ETL_NODISCARD ETL_CONSTEXPR14 front_insert_iterator& operator *()
753 {
754 return (*this);
755 }
756
757 //***************************************************************************
760 //***************************************************************************
762 {
763 return (*this);
764 }
765
766 //***************************************************************************
769 //***************************************************************************
771 {
772 return (*this);
773 }
774
775 protected:
776
777 TContainer* container;
778 };
779
780 //***************************************************************************
791 //***************************************************************************
792 template <typename TContainer>
793 ETL_NODISCARD
794 ETL_CONSTEXPR14
796 {
798 }
799
800 //***************************************************************************
801 // Helper templates.
802 //***************************************************************************
803 template <typename T>
805 {
806 static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::input_iterator_tag>::value;
807 };
808
809 template <typename T>
810 ETL_CONSTANT bool is_input_iterator<T>::value;
811
812 template <typename T>
814 {
815 static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::output_iterator_tag>::value;
816 };
817
818 template <typename T>
819 ETL_CONSTANT bool is_output_iterator<T>::value;
820
821 template <typename T>
823 {
824 static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::forward_iterator_tag>::value;
825 };
826
827 template <typename T>
828 ETL_CONSTANT bool is_forward_iterator<T>::value;
829
830 template <typename T>
832 {
833 static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::bidirectional_iterator_tag>::value;
834 };
835
836 template <typename T>
837 ETL_CONSTANT bool is_bidirectional_iterator<T>::value;
838
839 // Deprecated
840 template <typename T>
842 {
843 static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::random_access_iterator_tag>::value;
844 };
845
846 template <typename T>
847 ETL_CONSTANT bool is_random_iterator<T>::value;
848
849 template <typename T>
851 {
852 static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::random_access_iterator_tag>::value;
853 };
854
855 template <typename T>
856 ETL_CONSTANT bool is_random_access_iterator<T>::value;
857
858 template <typename T>
860 {
861 static ETL_CONSTANT bool value = etl::is_input_iterator<T>::value ||
865 };
866
867 template <typename T>
868 ETL_CONSTANT bool is_input_iterator_concept<T>::value;
869
870 template <typename T>
872 {
873 static ETL_CONSTANT bool value = etl::is_output_iterator<T>::value ||
877 };
878
879 template <typename T>
880 ETL_CONSTANT bool is_output_iterator_concept<T>::value;
881
882 template <typename T>
884 {
885 static ETL_CONSTANT bool value = etl::is_forward_iterator<T>::value ||
888 };
889
890 template <typename T>
892
893 template <typename T>
895 {
896 static ETL_CONSTANT bool value = etl::is_bidirectional_iterator<T>::value ||
898 };
899
900 template <typename T>
902
903 // Deprecated
904 template <typename T>
906 {
907 static ETL_CONSTANT bool value = etl::is_random_iterator<T>::value;
908 };
909
910 // Deprecated
911 template <typename T>
912 ETL_CONSTANT bool is_random_iterator_concept<T>::value;
913
914 // Deprecated
915 template <typename T>
917 {
918 static ETL_CONSTANT bool value = etl::is_random_access_iterator<T>::value;
919 };
920
921 // Deprecated
922 template <typename T>
924
925#if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
926 //*****************************************************************************
929 //*****************************************************************************
930 template<typename TContainer>
931 ETL_CONSTEXPR typename TContainer::iterator begin(TContainer& container)
932 {
933 return container.begin();
934 }
935
936 //*****************************************************************************
939 //*****************************************************************************
940 template<typename TContainer>
941 ETL_CONSTEXPR typename TContainer::const_iterator begin(const TContainer& container)
942 {
943 return container.begin();
944 }
945
946 //*****************************************************************************
949 //*****************************************************************************
950 template<typename TContainer>
951 ETL_CONSTEXPR typename TContainer::const_iterator cbegin(const TContainer& container)
952 {
953 return container.cbegin();
954 }
955
956 //*****************************************************************************
959 //*****************************************************************************
960 template<typename TContainer>
961 ETL_CONSTEXPR typename TContainer::iterator end(TContainer& container)
962 {
963 return container.end();
964 }
965
966 //*****************************************************************************
969 //*****************************************************************************
970 template<typename TContainer>
971 ETL_CONSTEXPR typename TContainer::const_iterator end(const TContainer& container)
972 {
973 return container.end();
974 }
975
976 //*****************************************************************************
979 //*****************************************************************************
980 template<typename TContainer>
981 ETL_CONSTEXPR typename TContainer::const_iterator cend(const TContainer& container)
982 {
983 return container.cend();
984 }
985
986 //*****************************************************************************
989 //*****************************************************************************
990 template<typename TValue, size_t Array_Size>
991 ETL_CONSTEXPR TValue* begin(TValue(&data)[Array_Size])
992 {
993 return &data[0];
994 }
995
996 //*****************************************************************************
999 //*****************************************************************************
1000 template<typename TValue, size_t Array_Size>
1001 ETL_CONSTEXPR const TValue* begin(const TValue(&data)[Array_Size])
1002 {
1003 return &data[0];
1004 }
1005
1006 //*****************************************************************************
1009 //*****************************************************************************
1010 template<typename TValue, size_t Array_Size>
1011 ETL_CONSTEXPR const TValue* cbegin(const TValue(&data)[Array_Size])
1012 {
1013 return &data[0];
1014 }
1015
1016 //*****************************************************************************
1019 //*****************************************************************************
1020 template<typename TValue, size_t Array_Size>
1021 ETL_CONSTEXPR TValue* end(TValue(&data)[Array_Size])
1022 {
1023 return &data[Array_Size];
1024 }
1025
1026 //*****************************************************************************
1029 //*****************************************************************************
1030 template<typename TValue, size_t Array_Size>
1031 ETL_CONSTEXPR const TValue* end(const TValue(&data)[Array_Size])
1032 {
1033 return &data[Array_Size];
1034 }
1035
1036 //*****************************************************************************
1039 //*****************************************************************************
1040 template<typename TValue, size_t Array_Size>
1041 ETL_CONSTEXPR const TValue* cend(const TValue(&data)[Array_Size])
1042 {
1043 return &data[Array_Size];
1044 }
1045#endif
1046
1047#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
1048 //*****************************************************************************
1051 //*****************************************************************************
1052 template<typename TContainer>
1053 ETL_CONSTEXPR typename TContainer::reverse_iterator rbegin(TContainer& container)
1054 {
1055 return container.rbegin();
1056 }
1057
1058 //*****************************************************************************
1061 //*****************************************************************************
1062 template<typename TContainer>
1063 ETL_CONSTEXPR typename TContainer::const_reverse_iterator rbegin(const TContainer& container)
1064 {
1065 return container.rbegin();
1066 }
1067
1068 //*****************************************************************************
1071 //*****************************************************************************
1072 template<typename TContainer>
1073 ETL_CONSTEXPR typename TContainer::const_reverse_iterator crbegin(const TContainer& container)
1074 {
1075 return container.crbegin();
1076 }
1077
1078 //*****************************************************************************
1081 //*****************************************************************************
1082 template<typename TContainer>
1083 ETL_CONSTEXPR typename TContainer::reverse_iterator rend(TContainer& container)
1084 {
1085 return container.rend();
1086 }
1087
1088 //*****************************************************************************
1091 //*****************************************************************************
1092 template<typename TContainer>
1093 ETL_CONSTEXPR typename TContainer::const_reverse_iterator rend(const TContainer& container)
1094 {
1095 return container.rend();
1096 }
1097
1098 //*****************************************************************************
1101 //*****************************************************************************
1102 template<typename TContainer>
1103 ETL_CONSTEXPR typename TContainer::const_reverse_iterator crend(const TContainer& container)
1104 {
1105 return container.crend();
1106 }
1107
1108 //*****************************************************************************
1111 //*****************************************************************************
1112 template<typename TValue, size_t Array_Size>
1113 ETL_OR_STD::reverse_iterator<TValue*> rbegin(TValue(&data)[Array_Size])
1114 {
1115 return ETL_OR_STD::reverse_iterator<TValue*>(&data[Array_Size]);
1116 }
1117
1118 //*****************************************************************************
1121 //*****************************************************************************
1122 template<typename TValue, size_t Array_Size>
1123 ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crbegin(const TValue(&data)[Array_Size])
1124 {
1125 return ETL_OR_STD::reverse_iterator<const TValue*>(&data[Array_Size]);
1126 }
1127
1128 //*****************************************************************************
1131 //*****************************************************************************
1132 template<typename TValue, size_t Array_Size>
1133 ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<TValue*> rend(TValue(&data)[Array_Size])
1134 {
1135 return ETL_OR_STD::reverse_iterator<TValue*>(&data[0]);
1136 }
1137
1138 //*****************************************************************************
1141 //*****************************************************************************
1142 template<typename TValue, size_t Array_Size>
1143 ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crend(const TValue(&data)[Array_Size])
1144 {
1145 return ETL_OR_STD::reverse_iterator<const TValue*>(&data[0]);
1146 }
1147#endif
1148
1149#if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
1155 template<typename TContainer>
1156 ETL_CONSTEXPR typename TContainer::size_type size(const TContainer& container)
1157 {
1158 return container.size();
1159 }
1160
1165 template<typename TValue, size_t Array_Size>
1166 ETL_CONSTEXPR size_t size(TValue(&)[Array_Size])
1167 {
1168 return Array_Size;
1169 }
1170#endif
1171
1179 template <typename T, size_t Array_Size>
1180 char(&array_size(T(&array)[Array_Size]))[Array_Size];
1181
1182#define ETL_ARRAY_SIZE(a) sizeof(etl::array_size(a))
1183}
1184
1185#endif
1186
Turns assignment into insertion.
Definition: iterator.h:595
TContainer container_type
A nested typedef for the type of whatever container you used.
Definition: iterator.h:599
ETL_CONSTEXPR14 back_insert_iterator & operator++()
Definition: iterator.h:649
ETL_CONSTEXPR14 back_insert_iterator(TContainer &c)
The only way to create this iterator is with a container.
Definition: iterator.h:602
ETL_CONSTEXPR14 back_insert_iterator & operator=(const typename TContainer::value_type &value)
Definition: iterator.h:617
ETL_NODISCARD ETL_CONSTEXPR14 back_insert_iterator & operator*()
Definition: iterator.h:640
Turns assignment into insertion.
Definition: iterator.h:705
ETL_CONSTEXPR14 front_insert_iterator(TContainer &c)
Definition: iterator.h:715
ETL_CONSTEXPR14 front_insert_iterator & operator++()
Definition: iterator.h:761
TContainer container_type
A nested typedef for the type of whatever container you used.
Definition: iterator.h:709
ETL_NODISCARD ETL_CONSTEXPR14 front_insert_iterator & operator*()
Definition: iterator.h:752
ETL_CONSTEXPR14 front_insert_iterator & operator=(const typename TContainer::value_type &value)
Definition: iterator.h:731
Definition: iterator.h:228
ETL_CONSTEXPR17 T * addressof(T &t)
Definition: addressof.h:51
is_same
Definition: type_traits_generator.h:1041
bitset_ext
Definition: absolute.h:38
ETL_CONSTEXPR TContainer::reverse_iterator rend(TContainer &container)
Definition: iterator.h:1083
ETL_CONSTEXPR TContainer::const_reverse_iterator crbegin(const TContainer &container)
Definition: iterator.h:1073
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator-(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition: circular_iterator.h:672
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:684
ETL_NODISCARD ETL_CONSTEXPR14 etl::front_insert_iterator< TContainer > front_inserter(TContainer &container)
Definition: iterator.h:795
ETL_CONSTEXPR TContainer::reverse_iterator rbegin(TContainer &container)
Definition: iterator.h:1053
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:696
ETL_CONSTEXPR TContainer::const_iterator cbegin(const TContainer &container)
Definition: iterator.h:951
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
ETL_NODISCARD ETL_CONSTEXPR14 etl::back_insert_iterator< TContainer > back_inserter(TContainer &container)
Definition: iterator.h:682
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: iterator.h:931
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator+(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition: circular_iterator.h:659
ETL_CONSTEXPR TContainer::const_reverse_iterator crend(const TContainer &container)
Definition: iterator.h:1103
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition: iterator.h:981
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:657
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:672
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: iterator.h:961
Definition: iterator.h:53
Definition: iterator.h:52
Definition: iterator.h:50
Definition: iterator.h:895
Definition: iterator.h:832
Definition: iterator.h:884
Definition: iterator.h:823
Definition: iterator.h:860
Definition: iterator.h:805
Definition: iterator.h:872
Definition: iterator.h:814
Definition: iterator.h:917
Definition: iterator.h:851
Definition: iterator.h:906
Definition: iterator.h:842
Definition: iterator.h:63
iterator
Definition: iterator.h:399
Definition: iterator.h:51
Definition: iterator.h:54