Embedded Template Library  1.0
algorithm.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2014 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_ALGORITHM_INCLUDED
32 #define ETL_ALGORITHM_INCLUDED
33 
38 
39 #include <stdint.h>
40 #include <string.h>
41 
42 #include "platform.h"
43 #include "type_traits.h"
44 #include "container.h"
45 #include "iterator.h"
46 #include "functional.h"
47 #include "utility.h"
48 
49 #if ETL_USING_STL
50  #include <algorithm>
51  #include <utility>
52  #include <iterator>
53  #include <functional>
54 #endif
55 
56 #include "private/minmax_push.h"
57 
58 namespace etl
59 {
60  // Declare prototypes of the ETL's sort functions
61  template <typename TIterator>
62  void shell_sort(TIterator first, TIterator last);
63 
64  template <typename TIterator, typename TCompare>
65  void shell_sort(TIterator first, TIterator last, TCompare compare);
66 
67  template <typename TIterator>
68  void insertion_sort(TIterator first, TIterator last);
69 
70  template <typename TIterator, typename TCompare>
71  void insertion_sort(TIterator first, TIterator last, TCompare compare);
72 }
73 
74 //*****************************************************************************
75 // Algorithms defined by the ETL
76 //*****************************************************************************
77 namespace etl
78 {
79 #if ETL_NOT_USING_STL
80  //***************************************************************************
81  // iter_swap
82  template <typename TIterator1, typename TIterator2>
83  void iter_swap(TIterator1 a, TIterator2 b)
84  {
85  using ETL_OR_STD::swap; // Allow ADL
86  swap(*a, *b);
87  }
88 #else
89  //***************************************************************************
90  // iter_swap
91  template <typename TIterator1, typename TIterator2>
92  void iter_swap(TIterator1 a, TIterator2 b)
93  {
94  std::iter_swap(a, b);
95  }
96 #endif
97 
98 #if ETL_NOT_USING_STL
99  //***************************************************************************
100  // swap_ranges
101  template <typename T1terator1, typename TIterator2>
102  TIterator2 swap_ranges(T1terator1 first1,
103  T1terator1 last1,
104  TIterator2 first2)
105  {
106  while (first1 != last1)
107  {
108  iter_swap(first1++, first2++);
109  }
110 
111  return first2;
112  }
113 #else
114  //***************************************************************************
115  // swap_ranges
116  template <typename T1terator1, typename TIterator2>
117  TIterator2 swap_ranges(T1terator1 first1,
118  T1terator1 last1,
119  TIterator2 first2)
120  {
121  return std::swap_ranges(first1, last1, first2);
122  }
123 #endif
124 
125 #if ETL_NOT_USING_STL
126  //***************************************************************************
127  // copy
128  // Pointer
129  template <typename TIterator1, typename TIterator2>
133  copy(TIterator1 sb, TIterator1 se, TIterator2 db)
134  {
135  typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
136  typedef typename etl::iterator_traits<TIterator1>::difference_type difference_t;
137 
138  difference_t count = (se - sb);
139 
140  return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count;
141  }
142 
143  // Other iterator
144  template <typename TIterator1, typename TIterator2>
148  copy(TIterator1 sb, TIterator1 se, TIterator2 db)
149  {
150  while (sb != se)
151  {
152  *db++ = *sb++;
153  }
154 
155  return db;
156  }
157 #else
158  //***************************************************************************
159  // copy
160  template <typename TIterator1, typename TIterator2>
161  TIterator2 copy(TIterator1 sb, TIterator1 se, TIterator2 db)
162  {
163  return std::copy(sb, se, db);
164  }
165 #endif
166 
167 #if ETL_NOT_USING_STL
168  //***************************************************************************
169  // reverse_copy
170  template <typename TIterator1, typename TIterator2>
171  TIterator2 reverse_copy(TIterator1 sb, TIterator1 se, TIterator2 db)
172  {
173  while (sb != se)
174  {
175  *(db++) = *(--se);
176  }
177 
178  return db;
179  }
180 #else
181  //***************************************************************************
182  // reverse_copy
183  template <typename TIterator1, typename TIterator2>
184  TIterator2 reverse_copy(TIterator1 sb, TIterator1 se, TIterator2 db)
185  {
186  return std::reverse_copy(sb, se, db);
187  }
188 #endif
189 
190 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
191  //***************************************************************************
192  // copy_n
193  // Pointer
194  template <typename TIterator1, typename TSize, typename TIterator2>
198  copy_n(TIterator1 sb, TSize count, TIterator2 db)
199  {
200  typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
201 
202  return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count;
203  }
204 
205  // Other iterator
206  template <typename TIterator1, typename TSize, typename TIterator2>
210  copy_n(TIterator1 sb, TSize count, TIterator2 db)
211  {
212  while (count != 0)
213  {
214  *db++ = *sb++;
215  --count;
216  }
217 
218  return db;
219  }
220 #else
221  //***************************************************************************
225  //***************************************************************************
226  template <typename TInputIterator, typename TSize, typename TOutputIterator>
227  TOutputIterator copy_n(TInputIterator i_begin,
228  TSize n,
229  TOutputIterator o_begin)
230  {
231  return std::copy_n(i_begin, n, o_begin);
232  }
233 #endif
234 
235 #if ETL_NOT_USING_STL
236  //***************************************************************************
237  // copy_backward
238  // Pointer
239  template <typename TIterator1, typename TIterator2>
243  copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
244  {
245  typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
246 
247  const size_t length = (se - sb);
248 
249  return TIterator2(memmove(de - length, sb, sizeof(value_t) * length));
250  }
251 
252  // Other iterator
253  template <typename TIterator1, typename TIterator2>
257  copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
258  {
259  while (se != sb)
260  {
261  *(--de) = *(--se);
262  }
263 
264  return de;
265  }
266 #else
267  //***************************************************************************
268  // copy_backward
269  template <typename TIterator1, typename TIterator2>
270  TIterator2 copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
271  {
272  return std::copy_backward(sb, se, de);
273  }
274 #endif
275 
276 #if ETL_CPP11_SUPPORTED
277 #if ETL_NOT_USING_STL
278  //***************************************************************************
279  // move
280  // non-pointer or not trivially copyable
281  template <typename TIterator1, typename TIterator2>
285  move(TIterator1 sb, TIterator1 se, TIterator2 db)
286  {
287  while (sb != se)
288  {
289  *db++ = etl::move(*sb++);
290  }
291 
292  return db;
293  }
294 
295  // pointer and trivially copyable
296  template <typename TIterator1, typename TIterator2>
300  move(TIterator1 sb, TIterator1 se, TIterator2 db)
301  {
302  typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
303  typedef typename etl::iterator_traits<TIterator1>::difference_type difference_t;
304 
305  difference_t count = (se - sb);
306 
307  return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count;
308  }
309 #else
310  //***************************************************************************
311  // move
312  template <typename TIterator1, typename TIterator2>
313  TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
314  {
315  return std::move(sb, se, db);
316  }
317 #endif
318 #else
319  // C++03
320  //***************************************************************************
321  // move
322  template <typename TIterator1, typename TIterator2>
323  TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
324  {
325  // Move not supported. Defer to copy.
326  return etl::copy(sb, se, db);
327  }
328 #endif
329 
330 #if ETL_CPP11_SUPPORTED
331 #if ETL_NOT_USING_STL
332  //***************************************************************************
333  // move_backward
334  // non-pointer, non-pod
335  template <typename TIterator1, typename TIterator2>
339  move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
340  {
341  while (sb != se)
342  {
343  *(--de) = etl::move(*(--se));
344  }
345 
346  return de;
347  }
348 
349  // pointer and pod
350  template <typename TIterator1, typename TIterator2>
354  move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
355  {
356  typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
357  typedef typename etl::iterator_traits<TIterator1>::difference_type difference_t;
358 
359  difference_t count = (se - sb);
360  TIterator2 db = de - count;
361 
362  return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count;
363  }
364 #else
365  //***************************************************************************
366  // move_backward
367  template <typename TIterator1, typename TIterator2>
368  TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
369  {
370  return std::move_backward(sb, se, de);
371  }
372 #endif
373 #else
374  //***************************************************************************
375  // move_backward
376  template <typename TIterator1, typename TIterator2>
377  TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
378  {
379  // Move not supported. Defer to copy_backward.
380  return ETL_OR_STD::copy_backward(sb, se, de);
381  }
382 #endif
383 
384 #if ETL_NOT_USING_STL
385  //***************************************************************************
386  // reverse
387  // Pointers
388  template <typename TIterator>
390  reverse(TIterator b, TIterator e)
391  {
392  if (b != e)
393  {
394  while (b < --e)
395  {
396  etl::iter_swap(b, e);
397  ++b;
398  }
399  }
400  }
401 
402  // Other
403  template <typename TIterator>
405  reverse(TIterator b, TIterator e)
406  {
407  while ((b != e) && (b != --e))
408  {
409  etl::iter_swap(b++, e);
410  }
411  }
412 #else
413  //***************************************************************************
414  // reverse
415  template <typename TIterator>
416  void reverse(TIterator b, TIterator e)
417  {
418  std::reverse(b, e);
419  }
420 #endif
421 
422 #if ETL_NOT_USING_STL
423  //***************************************************************************
424  // lower_bound
425  template<typename TIterator, typename TValue, typename TCompare>
426  ETL_NODISCARD
427  TIterator lower_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
428  {
429  typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
430 
431  difference_t count = etl::distance(first, last);
432 
433  while (count > 0)
434  {
435  TIterator itr = first;
436  difference_t step = count / 2;
437 
438  etl::advance(itr, step);
439 
440  if (compare(*itr, value))
441  {
442  first = ++itr;
443  count -= step + 1;
444  }
445  else
446  {
447  count = step;
448  }
449  }
450 
451  return first;
452  }
453 
454  template<typename TIterator, typename TValue>
455  ETL_NODISCARD
456  TIterator lower_bound(TIterator first, TIterator last, const TValue& value)
457  {
459 
460  return etl::lower_bound(first, last, value, compare());
461  }
462 #else
463  //***************************************************************************
464  // lower_bound
465  template<typename TIterator, typename TValue, typename TCompare>
466  ETL_NODISCARD
467  TIterator lower_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
468  {
469  return std::lower_bound(first, last, value, compare);
470  }
471 
472  template<typename TIterator, typename TValue>
473  ETL_NODISCARD
474  TIterator lower_bound(TIterator first, TIterator last, const TValue& value)
475  {
476  return std::lower_bound(first, last, value);
477  }
478 #endif
479 
480 #if ETL_NOT_USING_STL
481  //***************************************************************************
482  // upper_bound
483  template<typename TIterator, typename TValue, typename TCompare>
484  ETL_NODISCARD
485  TIterator upper_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
486  {
487  typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
488 
489  difference_t count = etl::distance(first, last);
490 
491  while (count > 0)
492  {
493  TIterator itr = first;
494  difference_t step = count / 2;
495 
496  etl::advance(itr, step);
497 
498  if (!compare(value, *itr))
499  {
500  first = ++itr;
501  count -= step + 1;
502  }
503  else
504  {
505  count = step;
506  }
507  }
508 
509  return first;
510  }
511 
512  template<typename TIterator, typename TValue>
513  ETL_NODISCARD
514  TIterator upper_bound(TIterator first, TIterator last, const TValue& value)
515  {
517 
518  return etl::upper_bound(first, last, value, compare());
519  }
520 #else
521  //***************************************************************************
522  // upper_bound
523  template<typename TIterator, typename TValue, typename TCompare>
524  ETL_NODISCARD
525  TIterator upper_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
526  {
527  return std::upper_bound(first, last, value, compare);
528  }
529 
530  template<typename TIterator, typename TValue>
531  ETL_NODISCARD
532  TIterator upper_bound(TIterator first, TIterator last, const TValue& value)
533  {
534  return std::upper_bound(first, last, value);
535  }
536 #endif
537 
538 #if ETL_NOT_USING_STL
539  //***************************************************************************
540  // equal_range
541  template<typename TIterator, typename TValue, typename TCompare>
542  ETL_NODISCARD
543  ETL_OR_STD::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value, TCompare compare)
544  {
545  return ETL_OR_STD::make_pair(etl::lower_bound(first, last, value, compare),
546  etl::upper_bound(first, last, value, compare));
547  }
548 
549  template<typename TIterator, typename TValue>
550  ETL_NODISCARD
551  ETL_OR_STD::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value)
552  {
554 
555  return ETL_OR_STD::make_pair(etl::lower_bound(first, last, value, compare()),
556  etl::upper_bound(first, last, value, compare()));
557  }
558 #else
559  //***************************************************************************
560  // equal_range
561  template<typename TIterator, typename TValue, typename TCompare>
562  ETL_NODISCARD
563  std::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value, TCompare compare)
564  {
565  return std::equal_range(first, last, value, compare);
566  }
567 
568  template<typename TIterator, typename TValue>
569  ETL_NODISCARD
570  std::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value)
571  {
572  return std::equal_range(first, last, value);
573  }
574 #endif
575 
576 #if ETL_NOT_USING_STL
577  //***************************************************************************
578  // find_if
579  template <typename TIterator, typename TUnaryPredicate>
580  ETL_NODISCARD
581  TIterator find_if(TIterator first, TIterator last, TUnaryPredicate predicate)
582  {
583  while (first != last)
584  {
585  if (predicate(*first))
586  {
587  return first;
588  }
589 
590  ++first;
591  }
592 
593  return last;
594  }
595 #else
596  //***************************************************************************
597  // find_if
598  template <typename TIterator, typename TUnaryPredicate>
599  ETL_NODISCARD
600  TIterator find_if(TIterator first, TIterator last, TUnaryPredicate predicate)
601  {
602  return std::find_if(first, last, predicate);
603  }
604 #endif
605 
606 #if ETL_NOT_USING_STL
607  //***************************************************************************
608  // find
609  template <typename TIterator, typename T>
610  ETL_NODISCARD
611  TIterator find(TIterator first, TIterator last, const T& value)
612  {
613  while (first != last)
614  {
615  if (*first == value)
616  {
617  return first;
618  }
619 
620  ++first;
621  }
622 
623  return last;
624  }
625 #else
626  //***************************************************************************
627  // find
628  template <typename TIterator, typename T>
629  ETL_NODISCARD
630  TIterator find(TIterator first, TIterator last, const T& value)
631  {
632  return std::find(first, last, value);
633  }
634 #endif
635 
636 #if ETL_NOT_USING_STL
637  //***************************************************************************
638  // fill
639  template<typename TIterator, typename TValue>
641  fill(TIterator first, TIterator last, const TValue& value)
642  {
643  while (first != last)
644  {
645  *first++ = value;
646  }
647  }
648 
649  template<typename TIterator, typename TValue>
651  fill(TIterator first, TIterator last, const TValue& value)
652  {
653  memset(first, value, last - first);
654  }
655 #else
656  //***************************************************************************
657  // fill
658  template<typename TIterator, typename TValue>
659  void fill(TIterator first, TIterator last, const TValue& value)
660  {
661  std::fill(first, last, value);
662  }
663 #endif
664 
665 #if ETL_NOT_USING_STL
666  //***************************************************************************
667  // fill_n
668  template<typename TIterator, typename TSize, typename TValue>
670  fill_n(TIterator first, TSize count, const TValue& value)
671  {
672  for (TSize i = 0; i < count; ++i)
673  {
674  *first++ = value;
675  }
676 
677  return first;
678  }
679 
680  template<typename TIterator, typename TSize, typename TValue>
682  fill_n(TIterator first, TSize count, const TValue& value)
683  {
684  memset(first, value, count);
685  }
686 #else
687  //***************************************************************************
688  // fill_n
689  template<typename TIterator, typename TSize, typename TValue>
690  TIterator fill_n(TIterator first, TSize count, const TValue& value)
691  {
692 #if ETL_CPP11_SUPPORTED
693  return std::fill_n(first, count, value);
694 #else
695  std::fill_n(first, count, value);
696  std::advance(first, count);
697  return first;
698 #endif
699  }
700 #endif
701 
702 #if ETL_NOT_USING_STL
703  //***************************************************************************
704  // count
705  template <typename TIterator, typename T>
706  ETL_NODISCARD
707  typename etl::iterator_traits<TIterator>::difference_type count(TIterator first, TIterator last, const T& value)
708  {
709  typename iterator_traits<TIterator>::difference_type n = 0;
710 
711  while (first != last)
712  {
713  if (*first == value)
714  {
715  ++n;
716  }
717 
718  ++first;
719  }
720 
721  return n;
722  }
723 #else
724  //***************************************************************************
725  // count
726  template <typename TIterator, typename T>
727  ETL_NODISCARD
728  typename std::iterator_traits<TIterator>::difference_type count(TIterator first, TIterator last, const T& value)
729  {
730  return std::count(first, last, value);
731  }
732 #endif
733 
734 #if ETL_NOT_USING_STL
735  //***************************************************************************
736  // count_if
737  template <typename TIterator, typename TUnaryPredicate>
738  ETL_NODISCARD
739  typename etl::iterator_traits<TIterator>::difference_type count_if(TIterator first, TIterator last, TUnaryPredicate predicate)
740  {
741  typename iterator_traits<TIterator>::difference_type n = 0;
742 
743  while (first != last)
744  {
745  if (predicate(*first))
746  {
747  ++n;
748  }
749 
750  ++first;
751  }
752 
753  return n;
754  }
755 #else
756  //***************************************************************************
757  // count_if
758  template <typename TIterator, typename TUnaryPredicate>
759  ETL_NODISCARD
760  typename std::iterator_traits<TIterator>::difference_type count_if(TIterator first, TIterator last, TUnaryPredicate predicate)
761  {
762  return std::count_if(first, last, predicate);
763  }
764 #endif
765 
766 #if ETL_NOT_USING_STL
767  //***************************************************************************
768  // equal
769  template <typename TIterator1, typename TIterator2>
770  ETL_NODISCARD
772  equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
773  {
774  while (first1 != last1)
775  {
776  if (*first1++ != *first2++)
777  {
778  return false;
779  }
780  }
781 
782  return true;
783  }
784 
785  template <typename TIterator1, typename TIterator2>
786  ETL_NODISCARD
788  equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
789  {
790  typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
791 
792  return (memcmp(first1, first2, sizeof(value_t) * (last1 - first1)) == 0);
793  }
794 
795  template <typename TIterator1, typename TIterator2>
796  ETL_NODISCARD
797  bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2)
798  {
799  return (etl::distance(first1, last1) == etl::distance(first2, last2)) &&
800  etl::equal(first1, last1, first2);
801  }
802 
803 #else
804  //***************************************************************************
805  // equal
806  template <typename TIterator1, typename TIterator2>
807  ETL_NODISCARD
808  bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
809  {
810  return std::equal(first1, last1, first2);
811  }
812 
813 #if ETL_CPP14_SUPPORTED
814  template <typename TIterator1, typename TIterator2>
815  ETL_NODISCARD
816  bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2)
817  {
818  return std::equal(first1, last1, first2, last2);
819  }
820 #else
821  template <typename TIterator1, typename TIterator2>
822  ETL_NODISCARD
823  bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2)
824  {
825  return (etl::distance(first1, last1) == etl::distance(first2, last2)) &&
826  etl::equal(first1, last1, first2);
827  }
828 #endif
829 #endif
830 
831 #if ETL_NOT_USING_STL
832  //***************************************************************************
833  // lexicographical_compare
834  template <typename TIterator1, typename TIterator2, typename TCompare>
835  ETL_NODISCARD
836  bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
837  TIterator2 first2, TIterator2 last2,
838  TCompare compare)
839  {
840  while ((first1 != last1) && (first2 != last2))
841  {
842  if (compare(*first1, *first2))
843  {
844  return true;
845  }
846 
847  if (compare(*first2, *first1))
848  {
849  return false;
850  }
851 
852  ++first1;
853  ++first2;
854  }
855 
856  return (first1 == last1) && (first2 != last2);
857  }
858 
859  //***************************************************************************
860  // lexicographical_compare
861  template <typename TIterator1, typename TIterator2>
862  ETL_NODISCARD
863  bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
864  TIterator2 first2, TIterator2 last2)
865  {
867 
868  return etl::lexicographical_compare(first1, last1, first2, last2, compare());
869  }
870 #else
871  //***************************************************************************
872  // lexicographical_compare
873  template <typename TIterator1, typename TIterator2, typename TCompare>
874  ETL_NODISCARD
875  bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
876  TIterator2 first2, TIterator2 last2,
877  TCompare compare)
878  {
879  return std::lexicographical_compare(first1, last1, first2, last2, compare);
880  }
881 
882  //***************************************************************************
883  // lexicographical_compare
884  template <typename TIterator1, typename TIterator2>
885  ETL_NODISCARD
886  bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
887  TIterator2 first2, TIterator2 last2)
888  {
889  return std::lexicographical_compare(first1, last1, first2, last2);
890  }
891 #endif
892 
893 #if ETL_NOT_USING_STL
894  //***************************************************************************
895  // min
896  template <typename T, typename TCompare>
897  ETL_NODISCARD
898  ETL_CONSTEXPR const T& min(const T& a, const T& b, TCompare compare)
899  {
900  return (compare(a, b)) ? a : b;
901  }
902 
903  template <typename T>
904  ETL_NODISCARD
905  ETL_CONSTEXPR const T& min(const T& a, const T& b)
906  {
907  typedef etl::less<T> compare;
908 
909  return etl::min(a, b, compare());
910  }
911 #else
912  //***************************************************************************
913  // min
914  template <typename T, typename TCompare>
915  ETL_NODISCARD
916  ETL_CONSTEXPR const T& min(const T& a, const T& b, TCompare compare)
917  {
918  return std::min(a, b, compare);
919  }
920 
921  template <typename T>
922  ETL_NODISCARD
923  ETL_CONSTEXPR const T& min(const T& a, const T& b)
924  {
925  return std::min(a, b);
926  }
927 #endif
928 
929 #if ETL_NOT_USING_STL
930  //***************************************************************************
931  // max
932  template <typename T, typename TCompare>
933  ETL_NODISCARD
934  ETL_CONSTEXPR const T& max(const T& a, const T& b, TCompare compare)
935  {
936  return (compare(a, b)) ? b : a;
937  }
938 
939  template <typename T>
940  ETL_NODISCARD
941  ETL_CONSTEXPR const T& max(const T& a, const T& b)
942  {
943  typedef etl::less<T> compare;
944 
945  return etl::max(a, b, compare());
946  }
947 #else
948  //***************************************************************************
949  // max
950  template <typename T, typename TCompare>
951  ETL_NODISCARD
952  ETL_CONSTEXPR const T& max(const T& a, const T& b, TCompare compare)
953  {
954  return std::max(a, b, compare);
955  }
956 
957  template <typename T>
958  ETL_NODISCARD
959  ETL_CONSTEXPR const T& max(const T& a, const T& b)
960  {
961  return std::max(a, b);
962  }
963 #endif
964 
965 #if ETL_NOT_USING_STL
966  //***************************************************************************
967  // transform
968  template <typename TIteratorIn, typename TIteratorOut, typename TUnaryOperation>
969  TIteratorOut transform(TIteratorIn first1, TIteratorIn last1, TIteratorOut d_first, TUnaryOperation unary_operation)
970  {
971  while (first1 != last1)
972  {
973  *d_first++ = unary_operation(*first1++);
974  }
975 
976  return d_first;
977  }
978 
979  template <typename TIteratorIn1, typename TIteratorIn2, typename TIteratorOut, typename TBinaryOperation>
980  TIteratorOut transform(TIteratorIn1 first1, TIteratorIn1 last1, TIteratorIn2 first2, TIteratorOut d_first, TBinaryOperation binary_operation)
981  {
982  while (first1 != last1)
983  {
984  *d_first++ = binary_operation(*first1++, *first2++);
985  }
986 
987  return d_first;
988  }
989 #else
990  //***************************************************************************
991  // transform
992  template <typename TIteratorIn, typename TIteratorOut, typename TUnaryOperation>
993  TIteratorOut transform(TIteratorIn first1, TIteratorIn last1, TIteratorOut d_first, TUnaryOperation unary_operation)
994  {
995  return std::transform(first1, last1, d_first, unary_operation);;
996  }
997 
998  template <typename TIteratorIn1, typename TIteratorIn2, typename TIteratorOut, typename TBinaryOperation>
999  TIteratorOut transform(TIteratorIn1 first1, TIteratorIn1 last1, TIteratorIn2 first2, TIteratorOut d_first, TBinaryOperation binary_operation)
1000  {
1001  return std::transform(first1, last1, first2, d_first, binary_operation);
1002  }
1003 #endif
1004 
1005 #if ETL_NOT_USING_STL
1006  //***************************************************************************
1007  // replace
1008  template <typename TIterator, typename T>
1009  ETL_CONSTEXPR14 void replace(TIterator first, TIterator last, const T& old_value, const T& new_value)
1010  {
1011  while (first != last)
1012  {
1013  if (*first == old_value)
1014  {
1015  *first = new_value;
1016  }
1017 
1018  ++first;
1019  }
1020  }
1021 
1022  //***************************************************************************
1023  // replace_if
1024  template <typename TIterator, typename TPredicate, typename T>
1025  ETL_CONSTEXPR14 void replace_if(TIterator first, TIterator last, TPredicate predicate, const T& new_value)
1026  {
1027  while (first != last)
1028  {
1029  if (predicate(*first))
1030  {
1031  *first = new_value;
1032  }
1033 
1034  ++first;
1035  }
1036  }
1037 #else
1038  //***************************************************************************
1039  // replace
1040  template <typename TIterator, typename T>
1041  ETL_CONSTEXPR14 void replace(TIterator first, TIterator last, const T& old_value, const T& new_value)
1042  {
1043  std::replace(first, last, old_value, new_value);
1044  }
1045 
1046  //***************************************************************************
1047  // replace_if
1048  template <typename TIterator, typename TPredicate, typename T>
1049  ETL_CONSTEXPR14 void replace_if(TIterator first, TIterator last, TPredicate predicate, const T& new_value)
1050  {
1051  std::replace_if(first, last, predicate, new_value);
1052  }
1053 #endif
1054 
1055  //***************************************************************************
1056  // Heap
1057  namespace private_heap
1058  {
1059  // Push Heap Helper
1060  template <typename TIterator, typename TDistance, typename TValue, typename TCompare>
1061  void push_heap(TIterator first, TDistance value_index, TDistance top_index, TValue value, TCompare compare)
1062  {
1063  TDistance parent = (value_index - 1) / 2;
1064 
1065  while ((value_index > top_index) && compare(first[parent], value))
1066  {
1067  first[value_index] = etl::move(first[parent]);
1068  value_index = parent;
1069  parent = (value_index - 1) / 2;
1070  }
1071 
1072  first[value_index] = etl::move(value);
1073  }
1074 
1075  // Adjust Heap Helper
1076  template <typename TIterator, typename TDistance, typename TValue, typename TCompare>
1077  void adjust_heap(TIterator first, TDistance value_index, TDistance length, TValue value, TCompare compare)
1078  {
1079  TDistance top_index = value_index;
1080  TDistance child2nd = (2 * value_index) + 2;
1081 
1082  while (child2nd < length)
1083  {
1084  if (compare(first[child2nd], first[child2nd - 1]))
1085  {
1086  --child2nd;
1087  }
1088 
1089  first[value_index] = etl::move(first[child2nd]);
1090  value_index = child2nd;
1091  child2nd = 2 * (child2nd + 1);
1092  }
1093 
1094  if (child2nd == length)
1095  {
1096  first[value_index] = etl::move(first[child2nd - 1]);
1097  value_index = child2nd - 1;
1098  }
1099 
1100  push_heap(first, value_index, top_index, etl::move(value), compare);
1101  }
1102 
1103  // Is Heap Helper
1104  template <typename TIterator, typename TDistance, typename TCompare>
1105  bool is_heap(const TIterator first, const TDistance n, TCompare compare)
1106  {
1107  TDistance parent = 0;
1108 
1109  for (TDistance child = 1; child < n; ++child)
1110  {
1111  if (compare(first[parent], first[child]))
1112  {
1113  return false;
1114  }
1115 
1116  if ((child & 1) == 0)
1117  {
1118  ++parent;
1119  }
1120  }
1121 
1122  return true;
1123  }
1124  }
1125 
1126  #if ETL_NOT_USING_STL
1127  // Pop Heap
1128  template <typename TIterator, typename TCompare>
1129  void pop_heap(TIterator first, TIterator last, TCompare compare)
1130  {
1131  typedef typename etl::iterator_traits<TIterator>::value_type value_t;
1132  typedef typename etl::iterator_traits<TIterator>::difference_type distance_t;
1133 
1134  value_t value = etl::move(last[-1]);
1135  last[-1] = etl::move(first[0]);
1136 
1137  private_heap::adjust_heap(first, distance_t(0), distance_t(last - first - 1), etl::move(value), compare);
1138  }
1139 
1140  // Pop Heap
1141  template <typename TIterator>
1142  void pop_heap(TIterator first, TIterator last)
1143  {
1145 
1146  etl::pop_heap(first, last, compare());
1147  }
1148 
1149  // Push Heap
1150  template <typename TIterator, typename TCompare>
1151  void push_heap(TIterator first, TIterator last, TCompare compare)
1152  {
1153  typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
1154  typedef typename etl::iterator_traits<TIterator>::value_type value_t;
1155 
1156  private_heap::push_heap(first, difference_t(last - first - 1), difference_t(0), value_t(etl::move(*(last - 1))), compare);
1157  }
1158 
1159  // Push Heap
1160  template <typename TIterator>
1161  void push_heap(TIterator first, TIterator last)
1162  {
1164 
1165  etl::push_heap(first, last, compare());
1166  }
1167 
1168  // Make Heap
1169  template <typename TIterator, typename TCompare>
1170  void make_heap(TIterator first, TIterator last, TCompare compare)
1171  {
1172  typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
1173 
1174  if ((last - first) < 2)
1175  {
1176  return;
1177  }
1178 
1179  difference_t length = last - first;
1180  difference_t parent = (length - 2) / 2;
1181 
1182  while (true)
1183  {
1184  private_heap::adjust_heap(first, parent, length, etl::move(*(first + parent)), compare);
1185 
1186  if (parent == 0)
1187  {
1188  return;
1189  }
1190 
1191  --parent;
1192  }
1193  }
1194 
1195  // Make Heap
1196  template <typename TIterator>
1197  void make_heap(TIterator first, TIterator last)
1198  {
1200 
1201  etl::make_heap(first, last, compare());
1202  }
1203 
1204  // Is Heap
1205  template <typename TIterator>
1206  ETL_NODISCARD
1207  bool is_heap(TIterator first, TIterator last)
1208  {
1210 
1211  return private_heap::is_heap(first, last - first, compare());
1212  }
1213 
1214  // Is Heap
1215  template <typename TIterator, typename TCompare>
1216  ETL_NODISCARD
1217  bool is_heap(TIterator first, TIterator last, TCompare compare)
1218  {
1219  return private_heap::is_heap(first, last - first, compare);
1220  }
1221 
1222  // Sort Heap
1223  template <typename TIterator>
1224  void sort_heap(TIterator first, TIterator last)
1225  {
1226  while (first != last)
1227  {
1228  etl::pop_heap(first, last--);
1229  }
1230  }
1231 
1232  // Sort Heap
1233  template <typename TIterator, typename TCompare>
1234  void sort_heap(TIterator first, TIterator last, TCompare compare)
1235  {
1236  while (first != last)
1237  {
1238  etl::pop_heap(first, last--, compare);
1239  }
1240  }
1241 
1242 #else
1243  //***************************************************************************
1244  // Heap
1245  // Pop Heap
1246  template <typename TIterator, typename TCompare>
1247  void pop_heap(TIterator first, TIterator last, TCompare compare)
1248  {
1249  std::pop_heap(first, last, compare);
1250  }
1251 
1252  // Pop Heap
1253  template <typename TIterator>
1254  void pop_heap(TIterator first, TIterator last)
1255  {
1256  std::pop_heap(first, last);
1257  }
1258 
1259  // Push Heap
1260  template <typename TIterator, typename TCompare>
1261  void push_heap(TIterator first, TIterator last, TCompare compare)
1262  {
1263  std::push_heap(first, last, compare);
1264  }
1265 
1266  // Push Heap
1267  template <typename TIterator>
1268  void push_heap(TIterator first, TIterator last)
1269  {
1270  std::push_heap(first, last);
1271  }
1272 
1273  // Make Heap
1274  template <typename TIterator, typename TCompare>
1275  void make_heap(TIterator first, TIterator last, TCompare compare)
1276  {
1277  std::make_heap(first, last, compare);
1278  }
1279 
1280  // Make Heap
1281  template <typename TIterator>
1282  void make_heap(TIterator first, TIterator last)
1283  {
1284  std::make_heap(first, last);
1285  }
1286 
1287  // Is Heap
1288  template <typename TIterator, typename TCompare>
1289  ETL_NODISCARD
1290  bool is_heap(TIterator first, TIterator last, TCompare compare)
1291  {
1292 #if ETL_CPP11_SUPPORTED
1293  return std::is_heap(first, last, compare);
1294 #else
1295  return private_heap::is_heap(first, last - first, compare());
1296 #endif
1297  }
1298 
1299  // Is Heap
1300  template <typename TIterator>
1301  ETL_NODISCARD
1302  bool is_heap(TIterator first, TIterator last)
1303  {
1304 #if ETL_CPP11_SUPPORTED
1305  return std::is_heap(first, last);
1306 #else
1308  return private_heap::is_heap(first, last - first, compare());
1309 #endif
1310  }
1311 
1312  // Sort Heap
1313  template <typename TIterator, typename TCompare>
1314  void sort_heap(TIterator first, TIterator last, TCompare compare)
1315  {
1316  std::sort_heap(first, last, compare);
1317  }
1318 
1319  // Sort Heap
1320  template <typename TIterator>
1321  void sort_heap(TIterator first, TIterator last)
1322  {
1323  std::sort_heap(first, last);
1324  }
1325 
1326 #endif
1327 
1328 #if ETL_NOT_USING_STL
1329  //***************************************************************************
1330  // Search
1331  template<typename TIterator1, typename TIterator2, typename TCompare>
1332  ETL_NODISCARD
1333  TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last, TCompare compare)
1334  {
1335  while (true)
1336  {
1337  TIterator1 itr = first;
1338  TIterator2 search_itr = search_first;
1339 
1340  while (true)
1341  {
1342  if (search_itr == search_last)
1343  {
1344  return first;
1345  }
1346 
1347  if (itr == last)
1348  {
1349  return last;
1350  }
1351 
1352  if (!compare(*itr, *search_itr))
1353  {
1354  break;
1355  }
1356 
1357  ++itr;
1358  ++search_itr;
1359  }
1360 
1361  ++first;
1362  }
1363  }
1364 
1365  // Search
1366  template<typename TIterator1, typename TIterator2>
1367  ETL_NODISCARD
1368  TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last)
1369  {
1371 
1372  return etl::search(first, last, search_first, search_last, compare());
1373  }
1374 #else
1375  //***************************************************************************
1376  // Search
1377  template<typename TIterator1, typename TIterator2, typename TCompare>
1378  ETL_NODISCARD
1379  TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last, TCompare compare)
1380  {
1381  return std::search(first, last, search_first, search_last, compare);
1382  }
1383 
1384  // Search
1385  template<typename TIterator1, typename TIterator2>
1386  ETL_NODISCARD
1387  TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last)
1388  {
1389  return std::search(first, last, search_first, search_last);
1390  }
1391 #endif
1392 
1393 #if ETL_NOT_USING_STL
1394  //***************************************************************************
1395  // Rotate
1396  namespace private_algorithm
1397  {
1398  //*********************************
1399  template <typename TIterator>
1400  TIterator rotate_general(TIterator first, TIterator middle, TIterator last)
1401  {
1402  TIterator next = middle;
1403 
1404  while (first != next)
1405  {
1406  using ETL_OR_STD::swap; // Allow ADL
1407 
1408  swap(*first++, *next++);
1409 
1410  if (next == last)
1411  {
1412  next = middle;
1413  }
1414  else if (first == middle)
1415  {
1416  middle = next;
1417  }
1418  }
1419 
1420  return first;
1421  }
1422 
1423  //*********************************
1424  template <typename TIterator>
1425  TIterator rotate_left_by_one(TIterator first, TIterator last)
1426  {
1427  typedef typename etl::iterator_traits<TIterator>::value_type value_type;
1428 
1429  // Save the first item.
1430  value_type temp(etl::move(*first));
1431 
1432  // Move the rest.
1433  TIterator result = etl::move(etl::next(first), last, first);
1434 
1435  // Restore the first item in its rotated position.
1436  *result = etl::move(temp);
1437 
1438  // The new position of the first item.
1439  return result;
1440  }
1441 
1442  //*********************************
1443  template <typename TIterator>
1444  TIterator rotate_right_by_one(TIterator first, TIterator last)
1445  {
1446  typedef typename etl::iterator_traits<TIterator>::value_type value_type;
1447 
1448  // Save the last item.
1449  TIterator previous = etl::prev(last);
1450  value_type temp(etl::move(*previous));
1451 
1452  // Move the rest.
1453  TIterator result = etl::move_backward(first, previous, last);
1454 
1455  // Restore the last item in its rotated position.
1456  *first = etl::move(temp);
1457 
1458  // The new position of the first item.
1459  return result;
1460  }
1461  }
1462 
1463  //*********************************
1464  template<typename TIterator>
1465  TIterator rotate(TIterator first, TIterator middle, TIterator last)
1466  {
1467  if (etl::next(first) == middle)
1468  {
1469  return private_algorithm::rotate_left_by_one(first, last);
1470  }
1471 
1472  if (etl::next(middle) == last)
1473  {
1474  return private_algorithm::rotate_right_by_one(first, last);
1475  }
1476 
1477  return private_algorithm::rotate_general(first, middle, last);
1478  }
1479 #else
1480  //***************************************************************************
1481  // Rotate
1482  template<typename TIterator>
1483  TIterator rotate(TIterator first, TIterator middle, TIterator last)
1484  {
1485  return std::rotate(first, middle, last);
1486  }
1487 #endif
1488 
1489 #if ETL_NOT_USING_STL
1490  //***************************************************************************
1491  // find_end
1492  // Predicate
1493  template <typename TIterator1, typename TIterator2, typename TPredicate>
1494  ETL_NODISCARD
1495  TIterator1 find_end(TIterator1 b, TIterator1 e,
1496  TIterator2 sb, TIterator2 se,
1497  TPredicate predicate)
1498  {
1499  if (sb == se)
1500  {
1501  return e;
1502  }
1503 
1504  TIterator1 result = e;
1505 
1506  while (true)
1507  {
1508  TIterator1 new_result = etl::search(b, e, sb, se, predicate);
1509 
1510  if (new_result == e)
1511  {
1512  break;
1513  }
1514  else
1515  {
1516  result = new_result;
1517  b = result;
1518  ++b;
1519  }
1520  }
1521  return result;
1522  }
1523 
1524  // Default
1525  template <typename TIterator1, typename TIterator2>
1526  ETL_NODISCARD
1527  TIterator1 find_end(TIterator1 b, TIterator1 e,
1528  TIterator2 sb, TIterator2 se)
1529  {
1531 
1532  return find_end(b, e, sb, se, predicate());
1533  }
1534 #else
1535  //***************************************************************************
1536  // find_end
1537  // Predicate
1538  template <typename TIterator1, typename TIterator2, typename TPredicate>
1539  ETL_NODISCARD
1540  TIterator1 find_end(TIterator1 b, TIterator1 e,
1541  TIterator2 sb, TIterator2 se,
1542  TPredicate predicate)
1543  {
1544  return std::find_end(b, e, sb, se, predicate);
1545  }
1546 
1547  // Default
1548  template <typename TIterator1, typename TIterator2>
1549  ETL_NODISCARD
1550  TIterator1 find_end(TIterator1 b, TIterator1 e,
1551  TIterator2 sb, TIterator2 se)
1552  {
1553  return std::find_end(b, e, sb, se);
1554  }
1555 #endif
1556 
1557 #if ETL_NOT_USING_STL
1558  //***************************************************************************
1562  //***************************************************************************
1563  template <typename TIterator, typename TCompare>
1564  ETL_NODISCARD
1565  TIterator min_element(TIterator begin,
1566  TIterator end,
1567  TCompare compare)
1568  {
1569  TIterator minimum = begin;
1570 
1571  while (begin != end)
1572  {
1573  if (compare(*begin, *minimum))
1574  {
1575  minimum = begin;
1576  }
1577 
1578  ++begin;
1579  }
1580 
1581  return minimum;
1582  }
1583 
1584  //***************************************************************************
1588  //***************************************************************************
1589  template <typename TIterator>
1590  ETL_NODISCARD
1591  TIterator min_element(TIterator begin,
1592  TIterator end)
1593  {
1594  typedef typename etl::iterator_traits<TIterator>::value_type value_t;
1595 
1597  }
1598 #else
1599  //***************************************************************************
1603  //***************************************************************************
1604  template <typename TIterator, typename TCompare>
1605  ETL_NODISCARD
1606  TIterator min_element(TIterator begin,
1607  TIterator end,
1608  TCompare compare)
1609  {
1610  return std::min_element(begin, end, compare);
1611  }
1612 
1613  //***************************************************************************
1617  //***************************************************************************
1618  template <typename TIterator>
1619  ETL_NODISCARD
1620  TIterator min_element(TIterator begin,
1621  TIterator end)
1622  {
1623  return std::min_element(begin, end);
1624  }
1625 #endif
1626 
1627 #if ETL_NOT_USING_STL
1628  //***************************************************************************
1632  //***************************************************************************
1633  template <typename TIterator, typename TCompare>
1634  ETL_NODISCARD
1635  TIterator max_element(TIterator begin,
1636  TIterator end,
1637  TCompare compare)
1638  {
1639  TIterator maximum = begin;
1640 
1641  while (begin != end)
1642  {
1643  if (!compare(*begin, *maximum))
1644  {
1645  maximum = begin;
1646  }
1647 
1648  ++begin;
1649  }
1650 
1651  return maximum;
1652  }
1653 
1654  //***************************************************************************
1658  //***************************************************************************
1659  template <typename TIterator>
1660  ETL_NODISCARD
1661  TIterator max_element(TIterator begin,
1662  TIterator end)
1663  {
1664  typedef typename etl::iterator_traits<TIterator>::value_type value_t;
1665 
1667  }
1668 #else
1669  //***************************************************************************
1673  //***************************************************************************
1674  template <typename TIterator, typename TCompare>
1675  ETL_NODISCARD
1676  TIterator max_element(TIterator begin,
1677  TIterator end,
1678  TCompare compare)
1679  {
1680  return std::max_element(begin, end, compare);
1681  }
1682 
1683  //***************************************************************************
1687  //***************************************************************************
1688  template <typename TIterator>
1689  ETL_NODISCARD
1690  TIterator max_element(TIterator begin,
1691  TIterator end)
1692  {
1693  return std::max_element(begin, end);
1694  }
1695 #endif
1696 
1697 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
1698  //***************************************************************************
1702  //***************************************************************************
1703  template <typename TIterator, typename TCompare>
1704  ETL_NODISCARD
1705  ETL_OR_STD::pair<TIterator, TIterator> minmax_element(TIterator begin,
1706  TIterator end,
1707  TCompare compare)
1708  {
1709  TIterator minimum = begin;
1710  TIterator maximum = begin;
1711 
1712  while (begin != end)
1713  {
1714  if (compare(*begin, *minimum))
1715  {
1716  minimum = begin;
1717  }
1718 
1719  if (compare(*maximum, *begin))
1720  {
1721  maximum = begin;
1722  }
1723 
1724  ++begin;
1725  }
1726 
1727  return ETL_OR_STD::pair<TIterator, TIterator>(minimum, maximum);
1728  }
1729 
1730  //***************************************************************************
1734  //***************************************************************************
1735  template <typename TIterator>
1736  ETL_NODISCARD
1737  ETL_OR_STD::pair<TIterator, TIterator> minmax_element(TIterator begin,
1738  TIterator end)
1739  {
1740  typedef typename etl::iterator_traits<TIterator>::value_type value_t;
1741 
1743  }
1744 #else
1745  //***************************************************************************
1749 //***************************************************************************
1750  template <typename TIterator, typename TCompare>
1751  ETL_NODISCARD
1752  std::pair<TIterator, TIterator> minmax_element(TIterator begin,
1753  TIterator end,
1754  TCompare compare)
1755  {
1756  return std::minmax_element(begin, end, compare);
1757  }
1758 
1759  //***************************************************************************
1763  //***************************************************************************
1764  template <typename TIterator>
1765  ETL_NODISCARD
1766  std::pair<TIterator, TIterator> minmax_element(TIterator begin,
1767  TIterator end)
1768  {
1769  return std::minmax_element(begin, end);
1770  }
1771 #endif
1772 
1773 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
1774  //***************************************************************************
1778  //***************************************************************************
1779  template <typename T>
1780  ETL_NODISCARD
1781  ETL_OR_STD::pair<const T&, const T&> minmax(const T& a,
1782  const T& b)
1783  {
1784  return (b < a) ? ETL_OR_STD::pair<const T&, const T&>(b, a) : ETL_OR_STD::pair<const T&, const T&>(a, b);
1785  }
1786 
1787  //***************************************************************************
1791  //***************************************************************************
1792  template <typename T, typename TCompare>
1793  ETL_NODISCARD
1794  ETL_OR_STD::pair<const T&, const T&> minmax(const T& a,
1795  const T& b,
1796  TCompare compare)
1797  {
1798  return compare(b, a) ? ETL_OR_STD::pair<const T&, const T&>(b, a) : ETL_OR_STD::pair<const T&, const T&>(a, b);
1799  }
1800 #else
1801  //***************************************************************************
1805  //***************************************************************************
1806  template <typename T>
1807  ETL_NODISCARD
1808  std::pair<const T&, const T&> minmax(const T& a,
1809  const T& b)
1810  {
1811  return std::minmax(a, b);
1812  }
1813 
1814  //***************************************************************************
1818  //***************************************************************************
1819  template <typename T, typename TCompare>
1820  ETL_NODISCARD
1821  std::pair<const T&, const T&> minmax(const T& a,
1822  const T& b,
1823  TCompare compare)
1824  {
1825  return std::minmax(a, b, compare);
1826  }
1827 #endif
1828 
1829 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
1830  //***************************************************************************
1834  //***************************************************************************
1835  template <typename TIterator>
1836  ETL_NODISCARD
1837  TIterator is_sorted_until(TIterator begin,
1838  TIterator end)
1839  {
1840  if (begin != end)
1841  {
1842  TIterator next = begin;
1843 
1844  while (++next != end)
1845  {
1846  if (*next < *begin)
1847  {
1848  return next;
1849  }
1850 
1851  ++begin;
1852  }
1853  }
1854 
1855  return end;
1856  }
1857 
1858  //***************************************************************************
1862  //***************************************************************************
1863  template <typename TIterator, typename TCompare>
1864  ETL_NODISCARD
1865  TIterator is_sorted_until(TIterator begin,
1866  TIterator end,
1867  TCompare compare)
1868  {
1869  if (begin != end)
1870  {
1871  TIterator next = begin;
1872 
1873  while (++next != end)
1874  {
1875  if (compare(*next, *begin))
1876  {
1877  return next;
1878  }
1879 
1880  ++begin;
1881  }
1882  }
1883 
1884  return end;
1885  }
1886 #else
1887  //***************************************************************************
1891  //***************************************************************************
1892  template <typename TIterator>
1893  ETL_NODISCARD
1894  TIterator is_sorted_until(TIterator begin,
1895  TIterator end)
1896  {
1897  return std::is_sorted_until(begin, end);
1898  }
1899 
1900  //***************************************************************************
1904  //***************************************************************************
1905  template <typename TIterator, typename TCompare>
1906  ETL_NODISCARD
1907  TIterator is_sorted_until(TIterator begin,
1908  TIterator end,
1909  TCompare compare)
1910  {
1911  return std::is_sorted_until(begin, end, compare);
1912  }
1913 #endif
1914 
1915 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
1916  //***************************************************************************
1920  //***************************************************************************
1921  template<typename TIterator>
1922  ETL_NODISCARD
1923  bool is_sorted(TIterator begin,
1924  TIterator end)
1925  {
1926  return etl::is_sorted_until(begin, end) == end;
1927  }
1928 
1929  //***************************************************************************
1933  //***************************************************************************
1934  template<typename TIterator, typename TCompare>
1935  ETL_NODISCARD
1936  bool is_sorted(TIterator begin,
1937  TIterator end,
1938  TCompare compare)
1939  {
1940  return etl::is_sorted_until(begin, end, compare) == end;
1941  }
1942 #else
1943  //***************************************************************************
1947  //***************************************************************************
1948  template<typename TIterator>
1949  ETL_NODISCARD
1950  bool is_sorted(TIterator begin,
1951  TIterator end)
1952  {
1953  return std::is_sorted(begin, end);
1954  }
1955 
1956  //***************************************************************************
1960  //***************************************************************************
1961  template<typename TIterator, typename TCompare>
1962  ETL_NODISCARD
1963  bool is_sorted(TIterator begin,
1964  TIterator end,
1965  TCompare compare)
1966  {
1967  return std::is_sorted(begin, end, compare);
1968  }
1969 #endif
1970 
1971 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
1972  //***************************************************************************
1976  //***************************************************************************
1977  template <typename TIterator, typename TUnaryPredicate>
1978  ETL_NODISCARD
1979  TIterator find_if_not(TIterator begin,
1980  TIterator end,
1981  TUnaryPredicate predicate)
1982  {
1983  while (begin != end)
1984  {
1985  if (!predicate(*begin))
1986  {
1987  return begin;
1988  }
1989 
1990  ++begin;
1991  }
1992 
1993  return end;
1994  }
1995 #else
1996  //***************************************************************************
2000  //***************************************************************************
2001  template <typename TIterator, typename TUnaryPredicate>
2002  ETL_NODISCARD
2003  TIterator find_if_not(TIterator begin,
2004  TIterator end,
2005  TUnaryPredicate predicate)
2006  {
2007  return std::find_if_not(begin, end, predicate);
2008  }
2009 #endif
2010 
2011 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2012  //***************************************************************************
2016  //***************************************************************************
2017  template <typename TIterator1, typename TIterator2>
2018  ETL_NODISCARD
2019  bool is_permutation(TIterator1 begin1,
2020  TIterator1 end1,
2021  TIterator2 begin2)
2022  {
2023  if (begin1 != end1)
2024  {
2025  TIterator2 end2 = begin2;
2026 
2027  etl::advance(end2, etl::distance(begin1, end1));
2028 
2029  for (TIterator1 i = begin1; i != end1; ++i)
2030  {
2031  if (i == etl::find(begin1, i, *i))
2032  {
2033  size_t n = etl::count(begin2, end2, *i);
2034 
2035  if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
2036  {
2037  return false;
2038  }
2039  }
2040  }
2041  }
2042 
2043  return true;
2044  }
2045 
2046  //***************************************************************************
2050  //***************************************************************************
2051  template <typename TIterator1, typename TIterator2, typename TBinaryPredicate>
2052  ETL_NODISCARD
2053  bool is_permutation(TIterator1 begin1,
2054  TIterator1 end1,
2055  TIterator2 begin2,
2056  TBinaryPredicate predicate)
2057  {
2058  if (begin1 != end1)
2059  {
2060  TIterator2 end2 = begin2;
2061 
2062  etl::advance(end2, etl::distance(begin1, end1));
2063 
2064  for (TIterator1 i = begin1; i != end1; ++i)
2065  {
2066  if (i == etl::find_if(begin1, i, etl::bind1st(predicate, *i)))
2067  {
2068  size_t n = etl::count(begin2, end2, *i);
2069 
2070  if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
2071  {
2072  return false;
2073  }
2074  }
2075  }
2076  }
2077 
2078  return true;
2079  }
2080 
2081  //***************************************************************************
2085  //***************************************************************************
2086  template <typename TIterator1, typename TIterator2>
2087  ETL_NODISCARD
2088  bool is_permutation(TIterator1 begin1,
2089  TIterator1 end1,
2090  TIterator2 begin2,
2091  TIterator2 end2)
2092  {
2093  if (begin1 != end1)
2094  {
2095  for (TIterator1 i = begin1; i != end1; ++i)
2096  {
2097  if (i == etl::find(begin1, i, *i))
2098  {
2099  size_t n = etl::count(begin2, end2, *i);
2100 
2101  if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
2102  {
2103  return false;
2104  }
2105  }
2106  }
2107  }
2108 
2109  return true;
2110  }
2111 
2112  //***************************************************************************
2116  //***************************************************************************
2117  template <typename TIterator1, typename TIterator2, typename TBinaryPredicate>
2118  ETL_NODISCARD
2119  bool is_permutation(TIterator1 begin1,
2120  TIterator1 end1,
2121  TIterator2 begin2,
2122  TIterator2 end2,
2123  TBinaryPredicate predicate)
2124  {
2125  if (begin1 != end1)
2126  {
2127  for (TIterator1 i = begin1; i != end1; ++i)
2128  {
2129  if (i == etl::find_if(begin1, i, etl::bind1st(predicate, *i)))
2130  {
2131  size_t n = etl::count(begin2, end2, *i);
2132 
2133  if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
2134  {
2135  return false;
2136  }
2137  }
2138  }
2139  }
2140 
2141  return true;
2142  }
2143 #else
2144  //***************************************************************************
2148  //***************************************************************************
2149  template <typename TIterator1, typename TIterator2>
2150  ETL_NODISCARD
2151  bool is_permutation(TIterator1 begin1,
2152  TIterator1 end1,
2153  TIterator2 begin2)
2154  {
2155  return std::is_permutation(begin1, end1, begin2);
2156  }
2157 
2158  //***************************************************************************
2162  //***************************************************************************
2163  template <typename TIterator1, typename TIterator2, typename TBinaryPredicate>
2164  ETL_NODISCARD
2165  bool is_permutation(TIterator1 begin1,
2166  TIterator1 end1,
2167  TIterator2 begin2,
2168  TBinaryPredicate predicate)
2169  {
2170  return std::is_permutation(begin1, end1, begin2, predicate);
2171  }
2172 
2173  #if ETL_CPP14_SUPPORTED
2174  //***************************************************************************
2178  //***************************************************************************
2179  template <typename TIterator1, typename TIterator2>
2180  ETL_NODISCARD
2181  bool is_permutation(TIterator1 begin1,
2182  TIterator1 end1,
2183  TIterator2 begin2,
2184  TIterator2 end2)
2185  {
2186  return std::is_permutation(begin1, end1, begin2, end2);
2187  }
2188 
2189  //***************************************************************************
2193  //***************************************************************************
2194  template <typename TIterator1, typename TIterator2, typename TBinaryPredicate>
2195  ETL_NODISCARD
2196  bool is_permutation(TIterator1 begin1,
2197  TIterator1 end1,
2198  TIterator2 begin2,
2199  TIterator2 end2,
2200  TBinaryPredicate predicate)
2201  {
2202  return std::is_permutation(begin1, end1, begin2, end2, predicate);
2203  }
2204  #endif
2205 #endif
2206 
2207 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2208  //***************************************************************************
2212  //***************************************************************************
2213  template <typename TIterator, typename TUnaryPredicate>
2214  ETL_NODISCARD
2215  bool is_partitioned(TIterator begin,
2216  TIterator end,
2217  TUnaryPredicate predicate)
2218  {
2219  while (begin != end)
2220  {
2221  if (!predicate(*begin++))
2222  {
2223  break;
2224  }
2225  }
2226 
2227  while (begin != end)
2228  {
2229  if (predicate(*begin++))
2230  {
2231  return false;
2232  }
2233  }
2234 
2235  return true;
2236  }
2237 #else
2238  //***************************************************************************
2242  //***************************************************************************
2243  template <typename TIterator, typename TUnaryPredicate>
2244  ETL_NODISCARD
2245  bool is_partitioned(TIterator begin,
2246  TIterator end,
2247  TUnaryPredicate predicate)
2248  {
2249  return std::is_partitioned(begin, end, predicate);
2250  }
2251 #endif
2252 
2253 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2254  //***************************************************************************
2258  //***************************************************************************
2259  template <typename TIterator, typename TUnaryPredicate>
2260  ETL_NODISCARD
2261  TIterator partition_point(TIterator begin,
2262  TIterator end,
2263  TUnaryPredicate predicate)
2264  {
2265  while (begin != end)
2266  {
2267  if (!predicate(*begin))
2268  {
2269  return begin;
2270  }
2271 
2272  ++begin;
2273  }
2274 
2275  return begin;
2276  }
2277 #else
2278  //***************************************************************************
2282  //***************************************************************************
2283  template <typename TIterator, typename TUnaryPredicate>
2284  ETL_NODISCARD
2285  TIterator partition_point(TIterator begin,
2286  TIterator end,
2287  TUnaryPredicate predicate)
2288  {
2289  return std::partition_point(begin, end, predicate);
2290  }
2291 #endif
2292 
2293 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2294  //***************************************************************************
2299  //***************************************************************************
2300  template <typename TSource, typename TDestinationTrue, typename TDestinationFalse, typename TUnaryPredicate>
2301  ETL_OR_STD::pair<TDestinationTrue, TDestinationFalse> partition_copy(TSource begin,
2302  TSource end,
2303  TDestinationTrue destination_true,
2304  TDestinationFalse destination_false,
2305  TUnaryPredicate predicate)
2306  {
2307  while (begin != end)
2308  {
2309  if (predicate(*begin))
2310  {
2311  *destination_true++ = *begin++;
2312  }
2313  else
2314  {
2315  *destination_false++ = *begin++;
2316  }
2317  }
2318 
2319  return ETL_OR_STD::pair<TDestinationTrue, TDestinationFalse>(destination_true, destination_false);
2320  }
2321 #else
2322  //***************************************************************************
2327  //***************************************************************************
2328  template <typename TSource, typename TDestinationTrue, typename TDestinationFalse, typename TUnaryPredicate>
2329  std::pair<TDestinationTrue, TDestinationFalse> partition_copy(TSource begin,
2330  TSource end,
2331  TDestinationTrue destination_true,
2332  TDestinationFalse destination_false,
2333  TUnaryPredicate predicate)
2334  {
2335  return std::partition_copy(begin, end, destination_true, destination_false, predicate);
2336  }
2337 #endif
2338 
2339 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2340  //***************************************************************************
2344  //***************************************************************************
2345  template <typename TIterator, typename TOutputIterator, typename TUnaryPredicate>
2346  TOutputIterator copy_if(TIterator begin,
2347  TIterator end,
2348  TOutputIterator out,
2349  TUnaryPredicate predicate)
2350  {
2351  while (begin != end)
2352  {
2353  if (predicate(*begin))
2354  {
2355  *out++ = *begin;
2356  }
2357 
2358  ++begin;
2359  }
2360 
2361  return out;
2362  }
2363 #else
2364  //***************************************************************************
2368  //***************************************************************************
2369  template <typename TIterator, typename TOutputIterator, typename TUnaryPredicate>
2370  TOutputIterator copy_if(TIterator begin,
2371  TIterator end,
2372  TOutputIterator out,
2373  TUnaryPredicate predicate)
2374  {
2375  return std::copy_if(begin, end, out, predicate);
2376  }
2377 #endif
2378 
2379 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2380  //***************************************************************************
2384  //***************************************************************************
2385  template <typename TIterator, typename TUnaryPredicate>
2386  ETL_NODISCARD
2387  bool all_of(TIterator begin,
2388  TIterator end,
2389  TUnaryPredicate predicate)
2390  {
2391  return etl::find_if_not(begin, end, predicate) == end;
2392  }
2393 #else
2394  //***************************************************************************
2398  //***************************************************************************
2399  template <typename TIterator, typename TUnaryPredicate>
2400  ETL_NODISCARD
2401  bool all_of(TIterator begin,
2402  TIterator end,
2403  TUnaryPredicate predicate)
2404  {
2405  return std::all_of(begin, end, predicate);
2406  }
2407 #endif
2408 
2409 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2410  //***************************************************************************
2414  //***************************************************************************
2415  template <typename TIterator, typename TUnaryPredicate>
2416  ETL_NODISCARD
2417  bool any_of(TIterator begin,
2418  TIterator end,
2419  TUnaryPredicate predicate)
2420  {
2421  return etl::find_if(begin, end, predicate) != end;
2422  }
2423 #else
2424  //***************************************************************************
2428  //***************************************************************************
2429  template <typename TIterator, typename TUnaryPredicate>
2430  ETL_NODISCARD
2431  bool any_of(TIterator begin,
2432  TIterator end,
2433  TUnaryPredicate predicate)
2434  {
2435  return std::any_of(begin, end, predicate);
2436  }
2437 #endif
2438 
2439 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
2440  //***************************************************************************
2444  //***************************************************************************
2445  template <typename TIterator, typename TUnaryPredicate>
2446  ETL_NODISCARD
2447  bool none_of(TIterator begin,
2448  TIterator end,
2449  TUnaryPredicate predicate)
2450  {
2451  return etl::find_if(begin, end, predicate) == end;
2452  }
2453 #else
2454  //***************************************************************************
2458  //***************************************************************************
2459  template <typename TIterator, typename TUnaryPredicate>
2460  ETL_NODISCARD
2461  bool none_of(TIterator begin,
2462  TIterator end,
2463  TUnaryPredicate predicate)
2464  {
2465  return std::none_of(begin, end, predicate);
2466  }
2467 #endif
2468 
2469 #if ETL_NOT_USING_STL
2470  //***************************************************************************
2474  //***************************************************************************
2475  template <typename TIterator, typename TCompare>
2476  void sort(TIterator first, TIterator last, TCompare compare)
2477  {
2478  etl::shell_sort(first, last, compare);
2479  }
2480 
2481  //***************************************************************************
2484  //***************************************************************************
2485  template <typename TIterator>
2486  void sort(TIterator first, TIterator last)
2487  {
2488  etl::shell_sort(first, last, etl::less<typename etl::iterator_traits<TIterator>::value_type>());
2489  }
2490 
2491  //***************************************************************************
2496  //***************************************************************************
2497  template <typename TIterator, typename TCompare>
2498  void stable_sort(TIterator first, TIterator last, TCompare compare)
2499  {
2500  etl::insertion_sort(first, last, compare);
2501  }
2502 
2503  //***************************************************************************
2507  //***************************************************************************
2508  template <typename TIterator>
2509  void stable_sort(TIterator first, TIterator last)
2510  {
2511  etl::insertion_sort(first, last, etl::less<typename etl::iterator_traits<TIterator>::value_type>());
2512  }
2513 #else
2514  //***************************************************************************
2518  //***************************************************************************
2519  template <typename TIterator, typename TCompare>
2520  void sort(TIterator first, TIterator last, TCompare compare)
2521  {
2522  std::sort(first, last, compare);
2523  }
2524 
2525  //***************************************************************************
2528  //***************************************************************************
2529  template <typename TIterator>
2530  void sort(TIterator first, TIterator last)
2531  {
2532  std::sort(first, last);
2533  }
2534 
2535  //***************************************************************************
2540  //***************************************************************************
2541  template <typename TIterator, typename TCompare>
2542  void stable_sort(TIterator first, TIterator last, TCompare compare)
2543  {
2544  std::stable_sort(first, last, compare);
2545  }
2546 
2547  //***************************************************************************
2551  //***************************************************************************
2552  template <typename TIterator>
2553  void stable_sort(TIterator first, TIterator last)
2554  {
2555  std::stable_sort(first, last);
2556  }
2557 #endif
2558 }
2559 
2560 //*****************************************************************************
2561 // ETL extensions to the STL algorithms.
2562 //*****************************************************************************
2563 namespace etl
2564 {
2565  //***************************************************************************
2575  //***************************************************************************
2576  template <typename TInputIterator,
2577  typename TOutputIterator>
2579  etl::is_random_iterator<TOutputIterator>::value, TOutputIterator>::type
2580  copy_s(TInputIterator i_begin,
2581  TInputIterator i_end,
2582  TOutputIterator o_begin,
2583  TOutputIterator o_end)
2584  {
2585  size_t s_size = etl::distance(i_begin, i_end);
2586  size_t d_size = etl::distance(o_begin, o_end);
2587  size_t size = (s_size < d_size) ? s_size : d_size;
2588 
2589  return etl::copy(i_begin, i_begin + size, o_begin);
2590  }
2591 
2592  //***************************************************************************
2602  //***************************************************************************
2603  template <typename TInputIterator,
2604  typename TOutputIterator>
2606  !etl::is_random_iterator<TOutputIterator>::value, TOutputIterator>::type
2607  copy_s(TInputIterator i_begin,
2608  TInputIterator i_end,
2609  TOutputIterator o_begin,
2610  TOutputIterator o_end)
2611  {
2612  while ((i_begin != i_end) && (o_begin != o_end))
2613  {
2614  *o_begin++ = *i_begin++;
2615  }
2616 
2617  return o_begin;
2618  }
2619 
2620  //***************************************************************************
2624  //***************************************************************************
2625  template <typename TInputIterator,
2626  typename TSize,
2627  typename TOutputIterator>
2628  TOutputIterator copy_n_s(TInputIterator i_begin,
2629  TSize n,
2630  TOutputIterator o_begin,
2631  TOutputIterator o_end)
2632  {
2633  while ((n-- > 0) && (o_begin != o_end))
2634  {
2635  *o_begin++ = *i_begin++;
2636  }
2637 
2638  return o_begin;
2639  }
2640 
2641  //***************************************************************************
2645  //***************************************************************************
2646  template <typename TInputIterator,
2647  typename TSize1,
2648  typename TOutputIterator,
2649  typename TSize2>
2650  TOutputIterator copy_n_s(TInputIterator i_begin,
2651  TSize1 n1,
2652  TOutputIterator o_begin,
2653  TSize2 n2)
2654  {
2655  while ((n1-- > 0) && (n2-- > 0))
2656  {
2657  *o_begin++ = *i_begin++;
2658  }
2659 
2660  return o_begin;
2661  }
2662 
2663  //***************************************************************************
2668  //***************************************************************************
2669  template <typename TInputIterator,
2670  typename TOutputIterator,
2671  typename TUnaryPredicate>
2672  TOutputIterator copy_if_s(TInputIterator i_begin,
2673  TInputIterator i_end,
2674  TOutputIterator o_begin,
2675  TOutputIterator o_end,
2676  TUnaryPredicate predicate)
2677  {
2678  while ((i_begin != i_end) && (o_begin != o_end))
2679  {
2680  if (predicate(*i_begin))
2681  {
2682  *o_begin++ = *i_begin;
2683  }
2684 
2685  ++i_begin;
2686  }
2687 
2688  return o_begin;
2689  }
2690 
2691  //***************************************************************************
2695  //***************************************************************************
2696  template <typename TInputIterator,
2697  typename TSize,
2698  typename TOutputIterator,
2699  typename TUnaryPredicate>
2700  TOutputIterator copy_n_if(TInputIterator i_begin,
2701  TSize n,
2702  TOutputIterator o_begin,
2703  TUnaryPredicate predicate)
2704  {
2705  while (n-- > 0)
2706  {
2707  if (predicate(*i_begin))
2708  {
2709  *o_begin++ = *i_begin;
2710  }
2711 
2712  ++i_begin;
2713  }
2714 
2715  return o_begin;
2716  }
2717 
2718 #if ETL_CPP11_SUPPORTED
2719  //***************************************************************************
2729  //***************************************************************************
2730  template <typename TInputIterator,
2731  typename TOutputIterator>
2733  etl::is_random_iterator<TOutputIterator>::value, TOutputIterator>::type
2734  move_s(TInputIterator i_begin,
2735  TInputIterator i_end,
2736  TOutputIterator o_begin,
2737  TOutputIterator o_end)
2738  {
2739  size_t s_size = etl::distance(i_begin, i_end);
2740  size_t d_size = etl::distance(o_begin, o_end);
2741  size_t size = (s_size < d_size) ? s_size : d_size;
2742 
2743  return etl::move(i_begin, i_begin + size, o_begin);
2744  }
2745 
2746  //***************************************************************************
2756  //***************************************************************************
2757  template <typename TInputIterator,
2758  typename TOutputIterator>
2760  !etl::is_random_iterator<TOutputIterator>::value, TOutputIterator>::type
2761  move_s(TInputIterator i_begin,
2762  TInputIterator i_end,
2763  TOutputIterator o_begin,
2764  TOutputIterator o_end)
2765  {
2766  while ((i_begin != i_end) && (o_begin != o_end))
2767  {
2768  *o_begin++ = etl::move(*i_begin++);
2769  }
2770 
2771  return o_begin;
2772  }
2773 #else
2774  //***************************************************************************
2785  //***************************************************************************
2786  template <typename TInputIterator, typename TOutputIterator>
2787  TOutputIterator move_s(TInputIterator i_begin,
2788  TInputIterator i_end,
2789  TOutputIterator o_begin,
2790  TOutputIterator o_end)
2791  {
2792  // Move not supported. Defer to copy.
2793  return etl::copy_s(i_begin, i_end, o_begin, o_end);
2794  }
2795 #endif
2796 
2797  //***************************************************************************
2801  //***************************************************************************
2802  template <typename TIterator, typename TValue>
2803  ETL_NODISCARD
2804  TIterator binary_find(TIterator begin,
2805  TIterator end,
2806  const TValue& value)
2807  {
2808  TIterator it = etl::lower_bound(begin, end, value);
2809 
2810  if ((it == end) || (*it != value))
2811  {
2812  it = end;
2813  }
2814 
2815  return it;
2816  }
2817 
2818  //***************************************************************************
2822  //***************************************************************************
2823  template <typename TIterator,
2824  typename TValue,
2825  typename TBinaryPredicate,
2826  typename TBinaryEquality>
2827  ETL_NODISCARD
2828  TIterator binary_find(TIterator begin,
2829  TIterator end,
2830  const TValue& value,
2831  TBinaryPredicate predicate,
2832  TBinaryEquality equality)
2833  {
2834  TIterator it = etl::lower_bound(begin, end, value, predicate);
2835 
2836  if ((it == end) || !equality(*it, value))
2837  {
2838  it = end;
2839  }
2840 
2841  return it;
2842  }
2843 
2844  //***************************************************************************
2847  //***************************************************************************
2848  template <typename TIterator,
2849  typename TUnaryFunction,
2850  typename TUnaryPredicate>
2851  TUnaryFunction for_each_if(TIterator begin,
2852  const TIterator end,
2853  TUnaryFunction function,
2854  TUnaryPredicate predicate)
2855  {
2856  while (begin != end)
2857  {
2858  if (predicate(*begin))
2859  {
2860  function(*begin);
2861  }
2862 
2863  ++begin;
2864  }
2865 
2866  return function;
2867  }
2868 
2869  //***************************************************************************
2872  //***************************************************************************
2873  template <typename TIterator,
2874  typename TSize,
2875  typename TUnaryFunction>
2876  TIterator for_each_n(TIterator begin,
2877  TSize n,
2878  TUnaryFunction function)
2879  {
2880  while (n-- > 0)
2881  {
2882  function(*begin++);
2883  }
2884 
2885  return begin;
2886  }
2887 
2888  //***************************************************************************
2891  //***************************************************************************
2892  template <typename TIterator,
2893  typename TSize,
2894  typename TUnaryFunction,
2895  typename TUnaryPredicate>
2896  TIterator for_each_n_if(TIterator begin,
2897  TSize n,
2898  TUnaryFunction function,
2899  TUnaryPredicate predicate)
2900  {
2901  while (n-- > 0)
2902  {
2903  if (predicate(*begin))
2904  {
2905  function(*begin);
2906  }
2907 
2908  ++begin;
2909  }
2910 
2911  return begin;
2912  }
2913 
2914  //***************************************************************************
2919  //***************************************************************************
2920  template <typename TInputIterator, typename TOutputIterator, typename TUnaryFunction>
2921  TOutputIterator transform_s(TInputIterator i_begin,
2922  TInputIterator i_end,
2923  TOutputIterator o_begin,
2924  TOutputIterator o_end,
2925  TUnaryFunction function)
2926  {
2927  while ((i_begin != i_end) && (o_begin != o_end))
2928  {
2929  *o_begin++ = function(*i_begin++);
2930  }
2931 
2932  return o_begin;
2933  }
2934 
2935  //***************************************************************************
2940  //***************************************************************************
2941  template <typename TInputIterator,
2942  typename TSize,
2943  typename TOutputIterator,
2944  typename TUnaryFunction>
2945  void transform_n(TInputIterator i_begin,
2946  TSize n,
2947  TOutputIterator o_begin,
2948  TUnaryFunction function)
2949  {
2950  TInputIterator i_end(i_begin);
2951  etl::advance(i_end, n);
2952 
2953  etl::transform(i_begin, i_end, o_begin, function);
2954  }
2955 
2956  //***************************************************************************
2961  //***************************************************************************
2962  template <typename TInputIterator1,
2963  typename TInputIterator2,
2964  typename TSize,
2965  typename TOutputIterator,
2966  typename TBinaryFunction>
2967  void transform_n(TInputIterator1 i_begin1,
2968  TInputIterator2 i_begin2,
2969  TSize n,
2970  TOutputIterator o_begin,
2971  TBinaryFunction function)
2972  {
2973  TInputIterator1 i_end1(i_begin1);
2974  etl::advance(i_end1, n);
2975 
2976  etl::transform(i_begin1, i_end1, i_begin2, o_begin, function);
2977  }
2978 
2979  //***************************************************************************
2982  //***************************************************************************
2983  template <typename TInputIterator,
2984  typename TOutputIterator,
2985  typename TUnaryFunction,
2986  typename TUnaryPredicate>
2987  TOutputIterator transform_if(TInputIterator i_begin,
2988  const TInputIterator i_end,
2989  TOutputIterator o_begin,
2990  TUnaryFunction function,
2991  TUnaryPredicate predicate)
2992  {
2993  while (i_begin != i_end)
2994  {
2995  if (predicate(*i_begin))
2996  {
2997  *o_begin++ = function(*i_begin);
2998  }
2999 
3000  ++i_begin;
3001  }
3002 
3003  return o_begin;
3004  }
3005 
3006  //***************************************************************************
3009  //***************************************************************************
3010  template <typename TInputIterator1,
3011  typename TInputIterator2,
3012  typename TOutputIterator,
3013  typename TBinaryFunction,
3014  typename TBinaryPredicate>
3015  TOutputIterator transform_if(TInputIterator1 i_begin1,
3016  const TInputIterator1 i_end1,
3017  TInputIterator2 i_begin2,
3018  TOutputIterator o_begin,
3019  TBinaryFunction function,
3020  TBinaryPredicate predicate)
3021  {
3022  while (i_begin1 != i_end1)
3023  {
3024  if (predicate(*i_begin1, *i_begin2))
3025  {
3026  *o_begin++ = function(*i_begin1, *i_begin2);
3027  }
3028 
3029  ++i_begin1;
3030  ++i_begin2;
3031  }
3032 
3033  return o_begin;
3034  }
3035 
3036  //***************************************************************************
3039  //***************************************************************************
3040  template <typename TInputIterator,
3041  typename TSize,
3042  typename TOutputIterator,
3043  typename TUnaryFunction,
3044  typename TUnaryPredicate>
3045  TOutputIterator transform_n_if(TInputIterator i_begin,
3046  TSize n,
3047  TOutputIterator o_begin,
3048  TUnaryFunction function,
3049  TUnaryPredicate predicate)
3050  {
3051  while (n-- > 0)
3052  {
3053  if (predicate(*i_begin))
3054  {
3055  *o_begin++ = function(*i_begin);
3056  }
3057 
3058  ++i_begin;
3059  }
3060 
3061  return o_begin;
3062  }
3063 
3064  //***************************************************************************
3067  //***************************************************************************
3068  template <typename TInputIterator1,
3069  typename TInputIterator2,
3070  typename TSize,
3071  typename TOutputIterator,
3072  typename TBinaryFunction,
3073  typename TBinaryPredicate>
3074  TOutputIterator transform_n_if(TInputIterator1 i_begin1,
3075  TInputIterator2 i_begin2,
3076  TSize n,
3077  TOutputIterator o_begin,
3078  TBinaryFunction function,
3079  TBinaryPredicate predicate)
3080  {
3081  while (n-- > 0)
3082  {
3083  if (predicate(*i_begin1, *i_begin2))
3084  {
3085  *o_begin++ = function(*i_begin1, *i_begin2);
3086  }
3087 
3088  ++i_begin1;
3089  ++i_begin2;
3090  }
3091 
3092  return o_begin;
3093  }
3094 
3095  //***************************************************************************
3099  //***************************************************************************
3100  template <typename TSource, typename TDestinationTrue, typename TDestinationFalse,
3101  typename TUnaryFunctionTrue, typename TUnaryFunctionFalse,
3102  typename TUnaryPredicate>
3103  ETL_OR_STD::pair<TDestinationTrue, TDestinationFalse> partition_transform(TSource begin,
3104  TSource end,
3105  TDestinationTrue destination_true,
3106  TDestinationFalse destination_false,
3107  TUnaryFunctionTrue function_true,
3108  TUnaryFunctionFalse function_false,
3109  TUnaryPredicate predicate)
3110  {
3111  while (begin != end)
3112  {
3113  if (predicate(*begin))
3114  {
3115  *destination_true++ = function_true(*begin++);
3116  }
3117  else
3118  {
3119  *destination_false++ = function_false(*begin++);
3120  }
3121  }
3122 
3123  return ETL_OR_STD::pair<TDestinationTrue, TDestinationFalse>(destination_true, destination_false);
3124  }
3125 
3126  //***************************************************************************
3130  //***************************************************************************
3131  template <typename TSource1,
3132  typename TSource2,
3133  typename TDestinationTrue,
3134  typename TDestinationFalse,
3135  typename TBinaryFunctionTrue,
3136  typename TBinaryFunctionFalse,
3137  typename TBinaryPredicate>
3138  ETL_OR_STD::pair<TDestinationTrue, TDestinationFalse> partition_transform(TSource1 begin1,
3139  TSource1 end1,
3140  TSource2 begin2,
3141  TDestinationTrue destination_true,
3142  TDestinationFalse destination_false,
3143  TBinaryFunctionTrue function_true,
3144  TBinaryFunctionFalse function_false,
3145  TBinaryPredicate predicate)
3146  {
3147  while (begin1 != end1)
3148  {
3149  if (predicate(*begin1, *begin2))
3150  {
3151  *destination_true++ = function_true(*begin1++, *begin2++);
3152  }
3153  else
3154  {
3155  *destination_false++ = function_false(*begin1++, *begin2++);
3156  }
3157  }
3158 
3159  return ETL_OR_STD::pair<TDestinationTrue, TDestinationFalse>(destination_true, destination_false);
3160  }
3161 
3162  //***************************************************************************
3166  //***************************************************************************
3167  template <typename TIterator, typename TCompare>
3168  void shell_sort(TIterator first, TIterator last, TCompare compare)
3169  {
3170  if (first == last)
3171  {
3172  return;
3173  }
3174 
3175  typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
3176 
3177  difference_t n = etl::distance(first, last);
3178 
3179  for (difference_t i = n / 2; i > 0; i /= 2)
3180  {
3181  for (difference_t j = i; j < n; ++j)
3182  {
3183  for (difference_t k = j - i; k >= 0; k -= i)
3184  {
3185  TIterator itr1 = first;
3186  TIterator itr2 = first;
3187 
3188  etl::advance(itr1, k);
3189  etl::advance(itr2, k + i);
3190 
3191  if (compare(*itr2, *itr1))
3192  {
3193  etl::iter_swap(itr1, itr2);
3194  }
3195  }
3196  }
3197  }
3198  }
3199 
3200  //***************************************************************************
3203  //***************************************************************************
3204  template <typename TIterator>
3205  void shell_sort(TIterator first, TIterator last)
3206  {
3207  etl::shell_sort(first, last, etl::less<typename etl::iterator_traits<TIterator>::value_type>());
3208  }
3209 
3210  //***************************************************************************
3214  //***************************************************************************
3215  template <typename TIterator, typename TCompare>
3216  void insertion_sort(TIterator first, TIterator last, TCompare compare)
3217  {
3218  for (TIterator itr = first; itr != last; ++itr)
3219  {
3220  etl::rotate(etl::upper_bound(first, itr, *itr, compare), itr, etl::next(itr));
3221  }
3222  }
3223 
3224  //***************************************************************************
3227  //***************************************************************************
3228  template <typename TIterator>
3229  void insertion_sort(TIterator first, TIterator last)
3230  {
3231  etl::insertion_sort(first, last, etl::less<typename etl::iterator_traits<TIterator>::value_type>());
3232  }
3233 
3234  //***************************************************************************
3238  //***************************************************************************
3239  template <typename TIterator, typename TCompare >
3240  void heap_sort(TIterator first, TIterator last, TCompare compare)
3241  {
3242  if (!etl::is_heap(first, last, compare))
3243  {
3244  etl::make_heap(first, last, compare);
3245  }
3246 
3247  etl::sort_heap(first, last, compare);
3248  }
3249 
3250  //***************************************************************************
3253  //***************************************************************************
3254  template <typename TIterator>
3255  void heap_sort(TIterator first, TIterator last)
3256  {
3257  if (!etl::is_heap(first, last))
3258  {
3259  etl::make_heap(first, last);
3260  }
3261 
3262  etl::sort_heap(first, last);
3263  }
3264 
3265  //***************************************************************************
3267  //***************************************************************************
3268 #if ETL_CPP11_SUPPORTED
3269  template <typename T>
3270  ETL_NODISCARD
3271  constexpr const T& multimax(const T& a, const T& b)
3272  {
3273  return a < b ? b : a;
3274  }
3275 
3276  template <typename T, typename... Tx>
3277  ETL_NODISCARD
3278  constexpr const T& multimax(const T& t, const Tx&... tx)
3279  {
3280  return multimax(t, multimax(tx...));
3281  }
3282 #endif
3283 
3284  //***************************************************************************
3287  //***************************************************************************
3288 #if ETL_CPP11_SUPPORTED
3289  template <typename TCompare, typename T>
3290  ETL_NODISCARD
3291  constexpr const T& multimax_compare(TCompare compare, const T& a, const T& b)
3292  {
3293  return compare(a, b) ? b : a;
3294  }
3295 
3296  template <typename TCompare, typename T, typename... Tx>
3297  ETL_NODISCARD
3298  constexpr const T& multimax_compare(TCompare compare, const T& t, const Tx&... tx)
3299  {
3300  return multimax_compare(compare, t, multimax_compare(compare, tx...));
3301  }
3302 #endif
3303 
3304  //***************************************************************************
3306  //***************************************************************************
3307 #if ETL_CPP11_SUPPORTED
3308  template <typename T>
3309  ETL_NODISCARD
3310  constexpr const T& multimin(const T& a, const T& b)
3311  {
3312  return a < b ? a : b;
3313  }
3314 
3315  template <typename T, typename... Tx>
3316  ETL_NODISCARD
3317  constexpr const T& multimin(const T& t, const Tx&... tx)
3318  {
3319  return multimin(t, multimin(tx...));
3320  }
3321 #endif
3322 
3323  //***************************************************************************
3326  //***************************************************************************
3327 #if ETL_CPP11_SUPPORTED
3328  template <typename TCompare, typename T>
3329  ETL_NODISCARD
3330  constexpr const T& multimin_compare(TCompare compare, const T& a, const T& b)
3331  {
3332  return compare(a, b) ? a : b;
3333  }
3334 
3335  template <typename TCompare, typename T, typename... Tx>
3336  ETL_NODISCARD
3337  constexpr const T& multimin_compare(TCompare compare, const T& t, const Tx&... tx)
3338  {
3339  return multimin_compare(compare, t, multimin_compare(compare, tx...));
3340  }
3341 #endif
3342 
3343  //***************************************************************************
3345  //***************************************************************************
3346 #if ETL_CPP11_SUPPORTED
3347  template <typename TIterator>
3348  ETL_NODISCARD
3349  constexpr const TIterator& multimax_iter(const TIterator& a, const TIterator& b)
3350  {
3351  return *a < *b ? b : a;
3352  }
3353 
3354  template <typename TIterator, typename... TIteratorx>
3355  ETL_NODISCARD
3356  constexpr const TIterator& multimax_iter(const TIterator& t, const TIteratorx&... tx)
3357  {
3358  return multimax_iter(t, multimax_iter(tx...));
3359  }
3360 #endif
3361 
3362  //***************************************************************************
3365  //***************************************************************************
3366 #if ETL_CPP11_SUPPORTED
3367  template <typename TCompare, typename TIterator>
3368  ETL_NODISCARD
3369  constexpr const TIterator& multimax_iter_compare(TCompare compare, const TIterator& a, const TIterator& b)
3370  {
3371  return compare(*a, *b) ? b : a;
3372  }
3373 
3374  template <typename TCompare, typename TIterator, typename... TIteratorx>
3375  ETL_NODISCARD
3376  constexpr const TIterator& multimax_iter_compare(TCompare compare, const TIterator& t, const TIteratorx&... tx)
3377  {
3378  return multimax_iter_compare(compare, t, multimax_iter_compare(compare, tx...));
3379  }
3380 #endif
3381 
3382  //***************************************************************************
3384  //***************************************************************************
3385 #if ETL_CPP11_SUPPORTED
3386  template <typename TIterator>
3387  ETL_NODISCARD
3388  constexpr const TIterator& multimin_iter(const TIterator& a, const TIterator& b)
3389  {
3390  return *a < *b ? a : b;
3391  }
3392 
3393  template <typename TIterator, typename... Tx>
3394  ETL_NODISCARD
3395  constexpr const TIterator& multimin_iter(const TIterator& t, const Tx&... tx)
3396  {
3397  return multimin_iter(t, multimin_iter(tx...));
3398  }
3399 #endif
3400 
3401  //***************************************************************************
3404  //***************************************************************************
3405 #if ETL_CPP11_SUPPORTED
3406  template <typename TCompare, typename TIterator>
3407  ETL_NODISCARD
3408  constexpr const TIterator& multimin_iter_compare(TCompare compare, const TIterator& a, const TIterator& b)
3409  {
3410  return compare(*a, *b) ? a : b;
3411  }
3412 
3413  template <typename TCompare, typename TIterator, typename... Tx>
3414  ETL_NODISCARD
3415  constexpr const TIterator& multimin_iter_compare(TCompare compare, const TIterator& t, const Tx&... tx)
3416  {
3417  return multimin_iter_compare(compare, t, multimin_iter_compare(compare, tx...));
3418  }
3419 #endif
3420 }
3421 
3422 #include "private/minmax_pop.h"
3423 
3424 #endif
TOutputIterator copy_n_if(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TUnaryPredicate predicate)
Definition: algorithm.h:2700
ETL_NODISCARD bool any_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:2417
ETL_NODISCARD TIterator partition_point(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:2261
TOutputIterator transform_if(TInputIterator i_begin, const TInputIterator i_end, TOutputIterator o_begin, TUnaryFunction function, TUnaryPredicate predicate)
Definition: algorithm.h:2987
TUnaryFunction for_each_if(TIterator begin, const TIterator end, TUnaryFunction function, TUnaryPredicate predicate)
Definition: algorithm.h:2851
ETL_NODISCARD bool is_partitioned(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:2215
ETL_NODISCARD TIterator min_element(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:1606
void sort(TIterator first, TIterator last)
Definition: algorithm.h:2530
TOutputIterator transform_n_if(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TUnaryFunction function, TUnaryPredicate predicate)
Definition: algorithm.h:3045
TOutputIterator copy_n_s(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TOutputIterator o_end)
Definition: algorithm.h:2628
ETL_NODISCARD bool is_sorted(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:1936
ETL_NODISCARD TIterator is_sorted_until(TIterator begin, TIterator end)
Definition: algorithm.h:1837
ETL_NODISCARD bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2)
Definition: algorithm.h:2019
ETL_NODISCARD ETL_OR_STD::pair< TIterator, TIterator > minmax_element(TIterator begin, TIterator end)
Definition: algorithm.h:1737
ETL_NODISCARD TIterator binary_find(TIterator begin, TIterator end, const TValue &value)
Definition: algorithm.h:2804
ETL_NODISCARD TIterator is_sorted_until(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:1865
TOutputIterator copy_if(TIterator begin, TIterator end, TOutputIterator out, TUnaryPredicate predicate)
Definition: algorithm.h:2346
void shell_sort(TIterator first, TIterator last)
Definition: algorithm.h:3205
ETL_NODISCARD bool is_sorted(TIterator begin, TIterator end)
Definition: algorithm.h:1923
void sort(TIterator first, TIterator last, TCompare compare)
Definition: algorithm.h:2520
ETL_NODISCARD TIterator max_element(TIterator begin, TIterator end)
Definition: algorithm.h:1690
TOutputIterator transform_s(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TOutputIterator o_end, TUnaryFunction function)
Definition: algorithm.h:2921
TIterator for_each_n_if(TIterator begin, TSize n, TUnaryFunction function, TUnaryPredicate predicate)
Definition: algorithm.h:2896
ETL_OR_STD::pair< TDestinationTrue, TDestinationFalse > partition_transform(TSource begin, TSource end, TDestinationTrue destination_true, TDestinationFalse destination_false, TUnaryFunctionTrue function_true, TUnaryFunctionFalse function_false, TUnaryPredicate predicate)
Definition: algorithm.h:3103
TOutputIterator copy_if_s(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TOutputIterator o_end, TUnaryPredicate predicate)
Definition: algorithm.h:2672
ETL_NODISCARD bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TIterator2 end2, TBinaryPredicate predicate)
Definition: algorithm.h:2119
ETL_NODISCARD bool none_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:2447
TIterator for_each_n(TIterator begin, TSize n, TUnaryFunction function)
Definition: algorithm.h:2876
ETL_NODISCARD ETL_OR_STD::pair< const T &, const T & > minmax(const T &a, const T &b)
Definition: algorithm.h:1781
etl::enable_if< etl::is_random_iterator< TInputIterator >::value &&etl::is_random_iterator< TOutputIterator >::value, TOutputIterator >::type copy_s(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TOutputIterator o_end)
Definition: algorithm.h:2580
void insertion_sort(TIterator first, TIterator last)
Definition: algorithm.h:3229
ETL_OR_STD::pair< TDestinationTrue, TDestinationFalse > partition_copy(TSource begin, TSource end, TDestinationTrue destination_true, TDestinationFalse destination_false, TUnaryPredicate predicate)
Definition: algorithm.h:2301
ETL_NODISCARD bool all_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:2387
ETL_NODISCARD TIterator find_if_not(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:1979
ETL_NODISCARD TIterator min_element(TIterator begin, TIterator end)
Definition: algorithm.h:1620
void transform_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TUnaryFunction function)
Definition: algorithm.h:2945
TOutputIterator move_s(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TOutputIterator o_end)
Definition: algorithm.h:2787
ETL_NODISCARD ETL_OR_STD::pair< const T &, const T & > minmax(const T &a, const T &b, TCompare compare)
Definition: algorithm.h:1794
ETL_NODISCARD ETL_OR_STD::pair< TIterator, TIterator > minmax_element(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:1705
void stable_sort(TIterator first, TIterator last, TCompare compare)
Definition: algorithm.h:2542
ETL_NODISCARD TIterator max_element(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:1676
void heap_sort(TIterator first, TIterator last, TCompare compare)
Definition: algorithm.h:3240
void stable_sort(TIterator first, TIterator last)
Definition: algorithm.h:2553
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: container.h:49
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: container.h:99
enable_if
Definition: type_traits_generator.h:1228
is_pointer
Definition: type_traits_generator.h:1041
is_same
Definition: type_traits_generator.h:981
is_trivially_copyable
Definition: type_traits_generator.h:1191
Definition: absolute.h:37
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition: array.h:570
Definition: compare.h:52
Definition: functional.h:136
Definition: iterator.h:633
Definition: functional.h:112