File: iterator.h

package info (click to toggle)
etlcpp 20.39.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 18,232 kB
  • sloc: cpp: 245,721; ansic: 10,254; sh: 1,481; asm: 301; python: 281; makefile: 24
file content (1217 lines) | stat: -rw-r--r-- 39,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
///\file

/******************************************************************************
The MIT License(MIT)

Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com

Copyright(c) 2017 John Wellbelove

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#ifndef ETL_ITERATOR_INCLUDED
#define ETL_ITERATOR_INCLUDED

#include "platform.h"
#include "type_traits.h"
#include "utility.h"
#include "private/addressof.h"

#if ETL_USING_STL || defined(ETL_IN_UNIT_TEST)
  #include <iterator>
#endif

///\defgroup iterator iterator
///\ingroup utilities

namespace etl
{
  //***************************************************************************
  // iterator tags
  struct input_iterator_tag {};
  struct output_iterator_tag {};
  struct forward_iterator_tag : public input_iterator_tag {};
  struct bidirectional_iterator_tag : public forward_iterator_tag {};
  struct random_access_iterator_tag : public bidirectional_iterator_tag {};
  //struct contiguous_iterator_tag : public random_access_iterator_tag {};

  //***************************************************************************
  // iterator_traits

  // For anything not a fundamental type.
  template <typename TIterator, typename = typename etl::enable_if<!etl::is_fundamental<TIterator>::value, void>::type>
  struct iterator_traits
  {
    typedef typename TIterator::iterator_category iterator_category;
    typedef typename TIterator::value_type        value_type;
    typedef typename TIterator::difference_type   difference_type;
    typedef typename TIterator::pointer           pointer;
    typedef typename TIterator::reference         reference;
  };
 
  // For pointers.
  template <typename T>
  struct iterator_traits<T*, void>
  {
    typedef ETL_OR_STD::random_access_iterator_tag iterator_category;
    typedef T                                      value_type;
    typedef ptrdiff_t                              difference_type;
    typedef typename etl::remove_cv<T>::type*      pointer;
    typedef T&                                     reference;
  };

  // For const pointers.
  template <typename T>
  struct iterator_traits<const T*, void>
  {
    typedef ETL_OR_STD::random_access_iterator_tag  iterator_category;
    typedef T                                       value_type;
    typedef ptrdiff_t                               difference_type;
    typedef const typename etl::remove_cv<T>::type* pointer;
    typedef const T&                                reference;
  };

  //***************************************************************************
  // advance
  template <typename TIterator, typename TDistance>
  ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::output_iterator_tag)
  {
    while (n--)
    {
      ++itr;
    }
  }

  template <typename TIterator, typename TDistance>
  ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::forward_iterator_tag)
  {
    while (n--)
    {
      ++itr;
    }
  }

  template <typename TIterator, typename TDistance>
  ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::bidirectional_iterator_tag)
  {
    if (n > 0)
    {
      while (n--)
      {
        ++itr;
      }
    }
    else
    {
      while (n++)
      {
        --itr;
      }
    }
  }

  template <typename TIterator, typename TDistance>
  ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::random_access_iterator_tag)
  {
    itr += n;
  }

  template <typename TIterator, typename TDistance>
  ETL_CONSTEXPR14 void advance(TIterator& itr, TDistance n)
  {
    typedef typename etl::iterator_traits<TIterator>::iterator_category tag;

    advance_helper(itr, n, tag());
  }

  //***************************************************************************
  // distance
  template<typename TIterator>
  ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::input_iterator_tag)
  {
    typename etl::iterator_traits<TIterator>::difference_type d = 0;

    while (first != last)
    {
      ++d;
      ++first;
    }

    return d;
  }

  template<typename TIterator>
  ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::forward_iterator_tag)
  {
    typename etl::iterator_traits<TIterator>::difference_type d = 0;

    while (first != last)
    {
      ++d;
      ++first;
    }

    return d;
  }

  template<typename TIterator>
  ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::bidirectional_iterator_tag)
  {
    typename etl::iterator_traits<TIterator>::difference_type d = 0;

    while (first != last)
    {
      ++d;
      ++first;
    }

    return d;
  }

  template<typename TIterator>
  ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::random_access_iterator_tag)
  {
    return last - first;
  }

  template<typename TIterator>
  ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance(TIterator first, TIterator last)
  {
    typedef typename etl::iterator_traits<TIterator>::iterator_category tag;

    return distance_helper(first, last, tag());
  }

  //***************************************************************************
  // Previous
  template<typename TIterator>
  ETL_CONSTEXPR14 TIterator prev(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
  {
    etl::advance(itr, -n);

    return itr;
  }

  //***************************************************************************
  // Next
  template<typename TIterator>
  ETL_CONSTEXPR14 TIterator next(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
  {
    etl::advance(itr, n);

    return itr;
  }

  //***************************************************************************
  // reverse_iterator
  template <typename TIterator>
  class reverse_iterator
  {
  public:

    typedef typename iterator_traits<TIterator>::iterator_category iterator_category;
    typedef typename iterator_traits<TIterator>::value_type        value_type;
    typedef typename iterator_traits<TIterator>::difference_type   difference_type;
    typedef typename iterator_traits<TIterator>::pointer           pointer;
    typedef typename iterator_traits<TIterator>::reference         reference;

    typedef TIterator iterator_type;

    ETL_CONSTEXPR14 reverse_iterator()
      : current()
    {
    }

    ETL_CONSTEXPR14 explicit reverse_iterator(TIterator itr)
      : current(itr)
    {
    }

    template <typename TOther>
    ETL_CONSTEXPR14 reverse_iterator(const reverse_iterator<TOther>& other)
      : current(other.base())
    {
    }

    template<class TOther>
    ETL_CONSTEXPR14 reverse_iterator& operator =(const reverse_iterator<TOther>& other)
    {
      current = other.base();

      return (*this);
    }

    ETL_CONSTEXPR14 TIterator base() const
    {
      return current;
    }

    ETL_NODISCARD ETL_CONSTEXPR14 reference operator*() const
    {
      TIterator temp = current;

      return *(--temp);
    }

    ETL_NODISCARD ETL_CONSTEXPR14 pointer operator->() const
    {
      TIterator temp = current;

      return &(*--temp);
    }

    ETL_CONSTEXPR14 reverse_iterator& operator++()
    {
      --current;

      return *this;
    }

    ETL_CONSTEXPR14 reverse_iterator operator++(int)
    {
      reverse_iterator temp = *this;
      --current;

      return temp;
    }

    ETL_CONSTEXPR14 reverse_iterator& operator--()
    {
      ++current;

      return (*this);
    }

    ETL_CONSTEXPR14 reverse_iterator operator--(int)
    {
      reverse_iterator temp = *this;
      ++current;

      return temp;
    }

    ETL_CONSTEXPR14 reverse_iterator& operator+=(const difference_type offset)
    {
      current -= offset;

      return (*this);
    }

    ETL_CONSTEXPR14 reverse_iterator& operator-=(const difference_type offset)
    {
      current += offset;

      return (*this);
    }

    ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator operator+(const difference_type offset) const
    {
      return reverse_iterator(current - offset);
    }

    ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator operator-(const difference_type offset) const
    {
      return (reverse_iterator(current + offset));
    }

    ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](const difference_type offset) const
    {
      return (*(*this + offset));
    }

  protected:

    TIterator current;
  };

  template <typename TIterator>
  ETL_CONSTEXPR14 bool operator ==(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return lhs.base() == rhs.base();
  }

  template <typename TIterator>
  ETL_CONSTEXPR14 bool operator !=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return !(lhs == rhs);
  }

  template <typename TIterator>
  ETL_CONSTEXPR14 bool operator <(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return rhs.base() < lhs.base();
  }

  template <typename TIterator>
  ETL_CONSTEXPR14 bool operator >(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return rhs < lhs;
  }

  template <typename TIterator>
  ETL_CONSTEXPR14 bool operator <=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return !(rhs < lhs);
  }

  template <typename TIterator>
  ETL_CONSTEXPR14 bool operator >=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return !(lhs < rhs);
  }

  template <typename TIterator>
  ETL_CONSTEXPR14 typename reverse_iterator<TIterator>::difference_type operator -(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
  {
    return rhs.base() - lhs.base();
  }

  template <typename TIterator, class TDifference>
  ETL_CONSTEXPR14 reverse_iterator<TIterator> operator +(TDifference n, const reverse_iterator<TIterator>& itr)
  {
    return itr.operator +(n);
  }

  //***************************************************************************
  /// iterator
  //***************************************************************************
  template <typename TCategory, typename T, typename TDistance = ptrdiff_t, typename TPointer = T* , typename TReference = T& >
  struct iterator
  {
    typedef T          value_type;
    typedef TDistance  difference_type;
    typedef TPointer   pointer;
    typedef TReference reference;
    typedef TCategory  iterator_category;
  };

#if ETL_USING_CPP11
  //***************************************************************************
  // move_iterator
  template <typename TIterator>
  class move_iterator
  {
  public:

    typedef typename iterator_traits<TIterator>::iterator_category iterator_category;
    typedef typename iterator_traits<TIterator>::value_type        value_type;
    typedef typename iterator_traits<TIterator>::difference_type   difference_type;
    typedef TIterator    iterator_type;
    typedef TIterator    pointer;
    typedef value_type&& reference;

    move_iterator()
    {
    }

    explicit move_iterator(TIterator itr)
      : current(itr)
    {
    }

    template <typename U>
    move_iterator(const move_iterator<U>& itr)
      : current(itr.base())
    {
    }

    template <typename U>
    move_iterator& operator =(const move_iterator<U>& itr)
    {
      current = itr.current;
      return *this;
    }

    iterator_type base() const
    {
      return current;
    }

    pointer operator ->() const
    {
      return current;
    }

    reference operator *() const
    {
      return etl::move(*current);
    }

    move_iterator& operator++()
    {
      ++current;
      return *this;
    }

    move_iterator& operator--()
    {
      --current;
      return *this;
    }

    move_iterator operator++(int)
    {
      move_iterator temp = *this;
      ++current;
      return temp;
    }

    move_iterator operator--(int)
    {
      move_iterator temp = *this;
      --current;
      return temp;
    }

    move_iterator operator +(difference_type n) const
    {
      return move_iterator(current + n);
    }

    move_iterator operator -(difference_type n) const
    {
      return move_iterator(current - n);
    }

    move_iterator operator +=(difference_type n)
    {
      current += n;
      return *this;
    }

    move_iterator operator -=(difference_type n)
    {
      current -= n;
      return *this;
    }

    reference operator [](difference_type n) const
    {
      return etl::move(current[n]);
    }

  private:

    TIterator current;
  };

  template <typename TIterator>
  bool operator ==(const etl::move_iterator<TIterator>& lhs,
                   const etl::move_iterator<TIterator>& rhs)
  {
    return lhs.base() == rhs.base();
  }

  template <typename TIterator>
  bool operator !=(const etl::move_iterator<TIterator>& lhs,
                   const etl::move_iterator<TIterator>& rhs)
  {
    return !(lhs == rhs);
  }

  template <typename TIterator>
  bool operator <(const etl::move_iterator<TIterator>& lhs,
                  const etl::move_iterator<TIterator>& rhs)
  {
    return lhs.base() < rhs.base();
  }

  template <typename TIterator>
  bool operator <=(const etl::move_iterator<TIterator>& lhs,
                   const etl::move_iterator<TIterator>& rhs)
  {
    return !(rhs < lhs);
  }

  template <typename TIterator>
  bool operator >(const etl::move_iterator<TIterator>& lhs,
                  const etl::move_iterator<TIterator>& rhs)
  {
    return (rhs < lhs);
  }

  template <typename TIterator>
  bool operator >=(const etl::move_iterator<TIterator>& lhs,
                   const etl::move_iterator<TIterator>& rhs)
  {
    return !(lhs < rhs);
  }

  template <typename TIterator>
  move_iterator<TIterator> operator +(typename move_iterator<TIterator>::difference_type n,
                                      const move_iterator<TIterator>& rhs)
  {
    return rhs + n;
  }

  template <typename  TIterator1, typename TIterator2 >
  auto operator -(const move_iterator<TIterator1>& lhs,
                  const move_iterator<TIterator2>& rhs) -> decltype(lhs.base() - rhs.base())
  {
    return lhs.base() - rhs.base();
  }

  template <typename TIterator>
  etl::move_iterator<TIterator> make_move_iterator(TIterator itr)
  {
    return etl::move_iterator<TIterator>(itr);
  }

#endif //ETL_USING_CPP11

  //***************************************************************************
  // back_insert_iterator
  //***************************************************************************

  //***************************************************************************
  /// Turns assignment into push_back
  //***************************************************************************
  template <typename TContainer>
  class back_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
  {
  public:

    typedef TContainer container_type;

    //***************************************************************************
    /// Constructor
    //***************************************************************************
    explicit ETL_CONSTEXPR14 back_insert_iterator(TContainer& c)
      : container(etl::addressof(c))
    {
    }

    //***************************************************************************
    /// Assignment operator
    //***************************************************************************
    ETL_CONSTEXPR14 back_insert_iterator& operator =(const typename TContainer::value_type& value)
    {
      container->push_back(value);
      
      return (*this);
    }

#if ETL_USING_CPP11
    //***************************************************************************
    /// Move assignment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 back_insert_iterator& operator =(typename TContainer::value_type&& value)
    {
      container->push_back(etl::move(value));
      
      return (*this);
    }
#endif  // ETL_USING_CPP11

    //***************************************************************************
    /// Dereference operator.
    //***************************************************************************
    ETL_NODISCARD ETL_CONSTEXPR14 back_insert_iterator& operator *()
    {
      return (*this);
    }

    //***************************************************************************
    /// Pre-increment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 back_insert_iterator& operator ++()
    {
      return (*this);
    }

    //***************************************************************************
    /// Post-increment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 back_insert_iterator operator ++(int)
    {
      return (*this);
    }

  protected:

    TContainer* container;
  };

  //***************************************************************************
  /// Creates a back_insert_iterator from a container.
  //***************************************************************************
  template <typename TContainer>
  ETL_NODISCARD 
  ETL_CONSTEXPR14 
  etl::back_insert_iterator<TContainer> back_inserter(TContainer& container)
  {
    return etl::back_insert_iterator<TContainer>(container);
  }

  //***************************************************************************
  // front_insert_iterator
  //***************************************************************************

  //***************************************************************************
  /// Turns assignment into a push_front.
  //***************************************************************************
  template <typename TContainer>
  class front_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
  {
  public:

    typedef TContainer container_type;

    //***************************************************************************
    /// Constructor
    //***************************************************************************
    explicit ETL_CONSTEXPR14 front_insert_iterator(TContainer& c)
      : container(etl::addressof(c))
    {
    }

    //***************************************************************************
    /// Assignment operator
    //***************************************************************************
    ETL_CONSTEXPR14 front_insert_iterator& operator =(const typename TContainer::value_type& value)
    {
      container->push_front(value);
      return (*this);
    }

#if ETL_USING_CPP11
    //***************************************************************************
    /// Move assignment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 front_insert_iterator& operator =(typename TContainer::value_type&& value)
    {
      container->push_front(etl::move(value));
      return (*this);
    }
#endif  // ETL_USING_CPP11

    //***************************************************************************
    /// Dereference operator.
    //***************************************************************************
    ETL_NODISCARD ETL_CONSTEXPR14 front_insert_iterator& operator *()
    {
      return (*this);
    }

    //***************************************************************************
    /// Pre-increment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 front_insert_iterator& operator ++()
    {
      return (*this);
    }

    //***************************************************************************
    /// Post-increment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 front_insert_iterator operator ++(int)
    {
      return (*this);
    }

  protected:

    TContainer* container;
  };

  //***************************************************************************
  /// Creates a front_insert_iterator from a container.
  //***************************************************************************
  template <typename TContainer>
  ETL_NODISCARD
  ETL_CONSTEXPR14
  etl::front_insert_iterator<TContainer> front_inserter(TContainer& container)
  {
    return etl::front_insert_iterator<TContainer>(container);
  }

  //***************************************************************************
  // push_insert_iterator
  //***************************************************************************

  //***************************************************************************
  /// Turns assignment into a push.
  //***************************************************************************
  template <typename TContainer>
  class push_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
  {
  public:

    typedef TContainer container_type;

    //***************************************************************************
    /// Constructor
    //***************************************************************************
    explicit ETL_CONSTEXPR14 push_insert_iterator(TContainer& c)
      : container(etl::addressof(c))
    {
    }

    //***************************************************************************
    /// Assignment operator
    //***************************************************************************
    ETL_CONSTEXPR14 push_insert_iterator& operator =(const typename TContainer::value_type& value)
    {
      container->push(value);

      return (*this);
    }

#if ETL_USING_CPP11
    //***************************************************************************
    /// Move assignment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 push_insert_iterator& operator =(typename TContainer::value_type&& value)
    {
      container->push(etl::move(value));

      return (*this);
    }
#endif  // ETL_USING_CPP11

    //***************************************************************************
    /// Dereference operator.
    //***************************************************************************
    ETL_NODISCARD ETL_CONSTEXPR14 push_insert_iterator& operator *()
    {
      return (*this);
    }

    //***************************************************************************
    /// Pre-increment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 push_insert_iterator& operator ++()
    {
      return (*this);
    }

    //***************************************************************************
    /// Post-increment operator.
    //***************************************************************************
    ETL_CONSTEXPR14 push_insert_iterator operator ++(int)
    {
      return (*this);
    }

  protected:

    TContainer* container;
  };

  //***************************************************************************
  /// Creates a push_insert_iterator from a container.
  //***************************************************************************
  template <typename TContainer>
  ETL_NODISCARD
    ETL_CONSTEXPR14
    etl::push_insert_iterator<TContainer> push_inserter(TContainer& container)
  {
    return etl::push_insert_iterator<TContainer>(container);
  }

  //***************************************************************************
  // Helper templates.
  //***************************************************************************
  template <typename T>
  struct is_input_iterator
  {
    static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::input_iterator_tag>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_input_iterator<T>::value;

  template <typename T>
  struct is_output_iterator
  {
    static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::output_iterator_tag>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_output_iterator<T>::value;

  template <typename T>
  struct is_forward_iterator
  {
    static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::forward_iterator_tag>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_forward_iterator<T>::value;

  template <typename T>
  struct is_bidirectional_iterator
  {
    static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::bidirectional_iterator_tag>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_bidirectional_iterator<T>::value;

  // Deprecated
  template <typename T>
  struct is_random_iterator
  {
    static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::random_access_iterator_tag>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_random_iterator<T>::value;

  template <typename T>
  struct is_random_access_iterator
  {
    static ETL_CONSTANT bool value = etl::is_same<typename etl::iterator_traits<T>::iterator_category, ETL_OR_STD::random_access_iterator_tag>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_random_access_iterator<T>::value;

  template <typename T>
  struct is_input_iterator_concept
  {
    static ETL_CONSTANT bool value = etl::is_input_iterator<T>::value ||
                                               etl::is_forward_iterator<T>::value ||
                                               etl::is_bidirectional_iterator<T>::value ||
                                               etl::is_random_iterator<T>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_input_iterator_concept<T>::value;

  template <typename T>
  struct is_output_iterator_concept
  {
    static ETL_CONSTANT bool value = etl::is_output_iterator<T>::value ||
                                               etl::is_forward_iterator<T>::value ||
                                               etl::is_bidirectional_iterator<T>::value ||
                                               etl::is_random_iterator<T>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_output_iterator_concept<T>::value;

  template <typename T>
  struct is_forward_iterator_concept
  {
    static ETL_CONSTANT bool value = etl::is_forward_iterator<T>::value ||
                                               etl::is_bidirectional_iterator<T>::value ||
                                               etl::is_random_iterator<T>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_forward_iterator_concept<T>::value;

  template <typename T>
  struct is_bidirectional_iterator_concept
  {
    static ETL_CONSTANT bool value = etl::is_bidirectional_iterator<T>::value ||
                                               etl::is_random_iterator<T>::value;
  };

  template <typename T>
  ETL_CONSTANT bool is_bidirectional_iterator_concept<T>::value;

  // Deprecated
  template <typename T>
  struct is_random_iterator_concept
  {
    static ETL_CONSTANT bool value = etl::is_random_iterator<T>::value;
  };

  // Deprecated
  template <typename T>
  ETL_CONSTANT bool is_random_iterator_concept<T>::value;

  // Deprecated
  template <typename T>
  struct is_random_access_iterator_concept
  {
    static ETL_CONSTANT bool value = etl::is_random_access_iterator<T>::value;
  };

  // Deprecated
  template <typename T>
  ETL_CONSTANT bool is_random_access_iterator_concept<T>::value;

#if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
  //*****************************************************************************
  /// Get the 'begin' iterator.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::iterator begin(TContainer& container)
  {
    return container.begin();
  }

  //*****************************************************************************
  /// Get the 'begin' const_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_iterator begin(const TContainer& container)
  {
    return container.begin();
  }

  //*****************************************************************************
  /// Get the 'begin' const_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_iterator cbegin(const TContainer& container)
  {
    return container.cbegin();
  }

  //*****************************************************************************
  /// Get the 'end' iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::iterator end(TContainer& container)
  {
    return container.end();
  }

  //*****************************************************************************
  /// Get the 'end' const_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_iterator end(const TContainer& container)
  {
    return container.end();
  }

  //*****************************************************************************
  /// Get the 'end' const_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_iterator cend(const TContainer& container)
  {
    return container.cend();
  }

  //*****************************************************************************
  /// Get the 'begin' pointer for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR TValue* begin(TValue(&data)[Array_Size])
  {
    return &data[0];
  }

  //*****************************************************************************
  /// Get the 'begin' const iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR const TValue* begin(const TValue(&data)[Array_Size])
  {
    return &data[0];
  }

  //*****************************************************************************
  /// Get the 'begin' const iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR const TValue* cbegin(const TValue(&data)[Array_Size])
  {
    return &data[0];
  }

  //*****************************************************************************
  /// Get the 'end' iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR TValue* end(TValue(&data)[Array_Size])
  {
    return &data[Array_Size];
  }

  //*****************************************************************************
  /// Get the 'end' const iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR const TValue* end(const TValue(&data)[Array_Size])
  {
    return &data[Array_Size];
  }

  //*****************************************************************************
  /// Get the 'end' const iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR const TValue* cend(const TValue(&data)[Array_Size])
  {
    return &data[Array_Size];
  }
#endif

#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
  //*****************************************************************************
  /// Get the 'begin' reverse_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::reverse_iterator rbegin(TContainer& container)
  {
    return container.rbegin();
  }

  //*****************************************************************************
  /// Get the 'begin' reverse_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_reverse_iterator rbegin(const TContainer& container)
  {
    return container.rbegin();
  }

  //*****************************************************************************
  /// Get the 'begin' reverse_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_reverse_iterator crbegin(const TContainer& container)
  {
    return container.crbegin();
  }

  //*****************************************************************************
  /// Get the 'end' reverse_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::reverse_iterator rend(TContainer& container)
  {
    return container.rend();
  }

  //*****************************************************************************
  /// Get the 'end' reverse_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_reverse_iterator rend(const TContainer& container)
  {
    return container.rend();
  }

  //*****************************************************************************
  /// Get the 'end' reverse_iterator for a container.
  ///\ingroup container
  //*****************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::const_reverse_iterator crend(const TContainer& container)
  {
    return container.crend();
  }

  //*****************************************************************************
  /// Get the 'begin' reverse_iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_OR_STD::reverse_iterator<TValue*> rbegin(TValue(&data)[Array_Size])
  {
    return ETL_OR_STD::reverse_iterator<TValue*>(&data[Array_Size]);
  }

  //*****************************************************************************
  /// Get the 'begin' const reverse_iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crbegin(const TValue(&data)[Array_Size])
  {
    return ETL_OR_STD::reverse_iterator<const TValue*>(&data[Array_Size]);
  }

  //*****************************************************************************
  /// Get the 'end' reverse_iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<TValue*> rend(TValue(&data)[Array_Size])
  {
    return ETL_OR_STD::reverse_iterator<TValue*>(&data[0]);
  }

  //*****************************************************************************
  /// Get the 'end' const reverse_iterator for an array.
  ///\ingroup container
  //*****************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crend(const TValue(&data)[Array_Size])
  {
    return ETL_OR_STD::reverse_iterator<const TValue*>(&data[0]);
  }
#endif

#if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
  //**************************************************************************
  /// Get the size of a container.
  /// Expects the container to have defined 'size_type'.
  ///\ingroup container
  //**************************************************************************
  template<typename TContainer>
  ETL_CONSTEXPR typename TContainer::size_type size(const TContainer& container)
  {
    return container.size();
  }

  ///**************************************************************************
  /// Get the size of an array in elements at run time, or compile time if C++11 or above.
  ///\ingroup container
  ///**************************************************************************
  template<typename TValue, size_t Array_Size>
  ETL_CONSTEXPR size_t size(TValue(&)[Array_Size])
  {
    return Array_Size;
  }
#endif

  //**************************************************************************
  /// Get the size of an array in elements at compile time for C++03
  ///\code
  /// sizeof(array_size(array))
  ///\endcode
  ///\ingroup container
  //**************************************************************************
  template <typename T, size_t Array_Size>
  char(&array_size(T(&array)[Array_Size]))[Array_Size];

#define ETL_ARRAY_SIZE(a) sizeof(etl::array_size(a))
}

#endif