235 #ifndef EASTL_ALGORITHM_H
236 #define EASTL_ALGORITHM_H
239 #include <EASTL/internal/config.h>
240 #include <EASTL/type_traits.h>
241 #include <EASTL/internal/move_help.h>
242 #include <EASTL/internal/copy_help.h>
243 #include <EASTL/internal/fill_help.h>
244 #include <EASTL/initializer_list.h>
245 #include <EASTL/iterator.h>
246 #include <EASTL/functional.h>
247 #include <EASTL/utility.h>
248 #include <EASTL/internal/generic_iterator.h>
249 #include <EASTL/random.h>
251 EA_DISABLE_ALL_VC_WARNINGS();
253 #if defined(EA_COMPILER_MSVC) && (defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64))
259 EA_RESTORE_ALL_VC_WARNINGS();
261 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
303 template <
typename ForwardIterator>
304 ForwardIterator
min_element(ForwardIterator first, ForwardIterator last)
308 ForwardIterator currentMin = first;
310 while(++first != last)
312 if(*first < *currentMin)
335 template <
typename ForwardIterator,
typename Compare>
336 ForwardIterator
min_element(ForwardIterator first, ForwardIterator last, Compare compare)
340 ForwardIterator currentMin = first;
342 while(++first != last)
344 if(compare(*first, *currentMin))
367 template <
typename ForwardIterator>
368 ForwardIterator
max_element(ForwardIterator first, ForwardIterator last)
372 ForwardIterator currentMax = first;
374 while(++first != last)
376 if(*currentMax < *first)
399 template <
typename ForwardIterator,
typename Compare>
400 ForwardIterator
max_element(ForwardIterator first, ForwardIterator last, Compare compare)
404 ForwardIterator currentMax = first;
406 while(++first != last)
408 if(compare(*currentMax, *first))
417 #if EASTL_MINMAX_ENABLED
442 template <
typename T>
446 return b < a ? b : a;
449 template <
typename T>
451 min(
const T& a,
const T& b)
453 return b < a ? b : a;
456 inline EA_CONSTEXPR
float min(
float a,
float b) {
return b < a ? b : a; }
457 inline EA_CONSTEXPR
double min(
double a,
double b) {
return b < a ? b : a; }
458 inline EA_CONSTEXPR
long double min(
long double a,
long double b) {
return b < a ? b : a; }
470 template <
typename T>
474 return b < a ? b : a;
477 template <
typename T>
479 min_alt(
const T& a,
const T& b)
481 return b < a ? b : a;
484 inline EA_CONSTEXPR
float min_alt(
float a,
float b) {
return b < a ? b : a; }
485 inline EA_CONSTEXPR
double min_alt(
double a,
double b) {
return b < a ? b : a; }
486 inline EA_CONSTEXPR
long double min_alt(
long double a,
long double b) {
return b < a ? b : a; }
489 #if EASTL_MINMAX_ENABLED
515 template <
typename T,
typename Compare>
517 min(
const T& a,
const T& b, Compare compare)
519 return compare(b, a) ? b : a;
532 template <
typename T,
typename Compare>
534 min_alt(
const T& a,
const T& b, Compare compare)
536 return compare(b, a) ? b : a;
540 #if EASTL_MINMAX_ENABLED
556 template <
typename T>
560 return a < b ? b : a;
563 template <
typename T>
565 max(
const T& a,
const T& b)
567 return a < b ? b : a;
570 inline EA_CONSTEXPR
float max(
float a,
float b) {
return a < b ? b : a; }
571 inline EA_CONSTEXPR
double max(
double a,
double b) {
return a < b ? b : a; }
572 inline EA_CONSTEXPR
long double max(
long double a,
long double b) {
return a < b ? b : a; }
582 template <
typename T>
586 return a < b ? b : a;
589 template <
typename T>
591 max_alt(
const T& a,
const T& b)
593 return a < b ? b : a;
596 inline EA_CONSTEXPR
float max_alt(
float a,
float b) {
return a < b ? b : a; }
597 inline EA_CONSTEXPR
double max_alt(
double a,
double b) {
return a < b ? b : a; }
598 inline EA_CONSTEXPR
long double max_alt(
long double a,
long double b) {
return a < b ? b : a; }
601 #if EASTL_MINMAX_ENABLED
610 template <
typename T,
typename Compare>
612 max(
const T& a,
const T& b, Compare compare)
614 return compare(a, b) ? b : a;
624 template <
typename T,
typename Compare>
626 max_alt(
const T& a,
const T& b, Compare compare)
628 return compare(a, b) ? b : a;
634 template <
typename T >
642 template <
typename T,
typename Compare>
651 template <
typename T >
659 template <
typename T,
typename Compare>
676 template <
typename ForwardIterator,
typename Compare>
682 if(!(first == last) && !(++first == last))
684 if(compare(*first, *result.first))
686 result.second = result.first;
687 result.first = first;
690 result.second = first;
692 while(++first != last)
694 ForwardIterator i = first;
698 if(compare(*i, *result.first))
700 else if(!compare(*i, *result.second))
706 if(compare(*first, *i))
708 if(compare(*first, *result.first))
709 result.first = first;
711 if(!compare(*i, *result.second))
716 if(compare(*i, *result.first))
719 if(!compare(*first, *result.second))
720 result.second = first;
730 template <
typename ForwardIterator>
734 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
770 template <
typename T>
778 template <
typename T,
typename Compare>
780 minmax(
const T& a,
const T& b, Compare compare)
787 template <
typename T>
791 typedef typename std::initializer_list<T>::iterator iterator_type;
796 template <
typename T,
class Compare>
800 typedef typename std::initializer_list<T>::iterator iterator_type;
805 template <
typename T>
806 inline T&& median_impl(T&& a, T&& b, T&& c)
811 return eastl::forward<T>(b);
813 return eastl::forward<T>(c);
815 return eastl::forward<T>(a);
818 return eastl::forward<T>(a);
820 return eastl::forward<T>(c);
821 return eastl::forward<T>(b);
832 template <
typename T>
833 inline const T&
median(
const T& a,
const T& b,
const T& c)
835 return median_impl(a, b, c);
846 template <
typename T>
849 return eastl::forward<T>(median_impl(eastl::forward<T>(a), eastl::forward<T>(b), eastl::forward<T>(c)));
853 template <
typename T,
typename Compare>
854 inline T&& median_impl(T&& a, T&& b, T&& c, Compare compare)
859 return eastl::forward<T>(b);
860 else if(compare(a, c))
861 return eastl::forward<T>(c);
863 return eastl::forward<T>(a);
865 else if(compare(a, c))
866 return eastl::forward<T>(a);
867 else if(compare(b, c))
868 return eastl::forward<T>(c);
869 return eastl::forward<T>(b);
881 template <
typename T,
typename Compare>
882 inline const T&
median(
const T& a,
const T& b,
const T& c, Compare compare)
884 return median_impl<const T&, Compare>(a, b, c, compare);
895 template <
typename T,
typename Compare>
896 inline T&&
median(T&& a, T&& b, T&& c, Compare compare)
898 return eastl::forward<T>(median_impl<T&&, Compare>(eastl::forward<T>(a), eastl::forward<T>(b), eastl::forward<T>(c), compare));
908 template <
typename InputIterator,
typename Predicate>
909 inline bool all_of(InputIterator first, InputIterator last, Predicate p)
911 for(; first != last; ++first)
924 template <
typename InputIterator,
typename Predicate>
925 inline bool any_of(InputIterator first, InputIterator last, Predicate p)
927 for(; first != last; ++first)
940 template <
typename InputIterator,
typename Predicate>
941 inline bool none_of(InputIterator first, InputIterator last, Predicate p)
943 for(; first != last; ++first)
960 template <
typename ForwardIterator>
961 inline ForwardIterator
966 ForwardIterator i = first;
968 for(++i; i != last; ++i)
988 template <
typename ForwardIterator,
typename BinaryPredicate>
989 inline ForwardIterator
990 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate predicate)
994 ForwardIterator i = first;
996 for(++i; i != last; ++i)
998 if(predicate(*first, *i))
1027 template <
typename RandomAccessIterator,
typename UniformRandomNumberGenerator>
1028 void shuffle(RandomAccessIterator first, RandomAccessIterator last, UniformRandomNumberGenerator&& urng)
1032 typedef typename eastl::iterator_traits<RandomAccessIterator>::difference_type difference_type;
1033 typedef typename eastl::make_unsigned<difference_type>::type unsigned_difference_type;
1039 for(RandomAccessIterator i = first + 1; i != last; ++i)
1040 iter_swap(i, first + uid(urng, uniform_int_distribution_param_type(0, i - first)));
1063 template <
typename RandomAccessIterator,
typename RandomNumberGenerator>
1064 inline void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator&& rng)
1066 typedef typename eastl::iterator_traits<RandomAccessIterator>::difference_type difference_type;
1072 for(RandomAccessIterator i = first + 1; i < last; ++i)
1073 iter_swap(i, first + (difference_type)rng((eastl_size_t)((i - first) + 1)));
1106 template <
typename InputIterator,
typename Size,
typename OutputIterator>
1107 inline OutputIterator
1108 move_n_impl(InputIterator first, Size n, OutputIterator result, EASTL_ITC_NS::input_iterator_tag)
1115 template <
typename RandomAccessIterator,
typename Size,
typename OutputIterator>
1116 inline OutputIterator
1117 move_n_impl(RandomAccessIterator first, Size n, OutputIterator result, EASTL_ITC_NS::random_access_iterator_tag)
1123 template <
typename InputIterator,
typename Size,
typename OutputIterator>
1124 inline OutputIterator
1125 move_n(InputIterator first, Size n, OutputIterator result)
1127 typedef typename eastl::iterator_traits<InputIterator>::iterator_category IC;
1140 template <
typename InputIterator,
typename Size,
typename OutputIterator>
1141 inline OutputIterator
1142 copy_n_impl(InputIterator first, Size n, OutputIterator result, EASTL_ITC_NS::input_iterator_tag)
1145 *result++ = *first++;
1149 template <
typename RandomAccessIterator,
typename Size,
typename OutputIterator>
1150 inline OutputIterator
1151 copy_n_impl(RandomAccessIterator first, Size n, OutputIterator result, EASTL_ITC_NS::random_access_iterator_tag)
1157 template <
typename InputIterator,
typename Size,
typename OutputIterator>
1158 inline OutputIterator
1159 copy_n(InputIterator first, Size n, OutputIterator result)
1161 typedef typename eastl::iterator_traits<InputIterator>::iterator_category IC;
1170 template <
typename InputIterator,
typename OutputIterator,
typename Predicate>
1171 inline OutputIterator
1172 copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate predicate)
1175 for(; first != last; ++first)
1177 if(predicate(*first))
1188 template <
typename ,
bool ,
bool >
1191 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1192 static BidirectionalIterator2 move_or_copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1194 while(first != last)
1195 *--resultEnd = *--last;
1201 template <
typename B
idirectionalIterator1Category>
1204 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1205 static BidirectionalIterator2 move_or_copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1207 while(first != last)
1217 template<
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1218 static BidirectionalIterator2 move_or_copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1220 typedef typename eastl::iterator_traits<BidirectionalIterator1>::difference_type difference_type;
1222 for(difference_type n = (last - first); n > 0; --n)
1234 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1235 static BidirectionalIterator2 move_or_copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1237 typedef typename eastl::iterator_traits<BidirectionalIterator1>::difference_type difference_type;
1239 for(difference_type n = (last - first); n > 0; --n)
1240 *--resultEnd = *--last;
1246 template <
bool isMove>
1249 template <
typename T>
1250 static T* move_or_copy_backward(
const T* first,
const T* last, T* resultEnd)
1252 return (T*)__builtin_memmove(resultEnd - (last - first), first, (
size_t)((uintptr_t)last - (uintptr_t)first));
1257 template <
bool isMove,
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1258 inline BidirectionalIterator2 move_and_copy_backward_chooser(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1260 typedef typename eastl::iterator_traits<BidirectionalIterator1>::iterator_category IIC;
1261 typedef typename eastl::iterator_traits<BidirectionalIterator2>::iterator_category OIC;
1262 typedef typename eastl::iterator_traits<BidirectionalIterator1>::value_type value_type_input;
1263 typedef typename eastl::iterator_traits<BidirectionalIterator2>::value_type value_type_output;
1275 template <
bool isMove,
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1276 inline BidirectionalIterator2 move_and_copy_backward_unwrapper(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1278 return BidirectionalIterator2(eastl::move_and_copy_backward_chooser<isMove>(eastl::unwrap_iterator(first), eastl::unwrap_iterator(last), eastl::unwrap_iterator(resultEnd)));
1303 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1304 inline BidirectionalIterator2
move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1306 return eastl::move_and_copy_backward_unwrapper<true>(eastl::unwrap_iterator(first), eastl::unwrap_iterator(last), resultEnd);
1324 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
1325 inline BidirectionalIterator2
copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
1329 return eastl::move_and_copy_backward_unwrapper<isMove>(eastl::unwrap_iterator(first), eastl::unwrap_iterator(last), resultEnd);
1345 template <
typename InputIterator,
typename T>
1346 inline typename eastl::iterator_traits<InputIterator>::difference_type
1347 count(InputIterator first, InputIterator last,
const T& value)
1349 typename eastl::iterator_traits<InputIterator>::difference_type result = 0;
1351 for(; first != last; ++first)
1362 template <
typename InputIterator,
typename T,
typename Predicate>
1363 inline typename eastl::iterator_traits<InputIterator>::difference_type
1364 count(InputIterator first, InputIterator last,
const T& value, Predicate predicate)
1366 typename eastl::iterator_traits<InputIterator>::difference_type result = 0;
1368 for(; first != last; ++first)
1370 if(predicate(*first, value))
1390 template <
typename InputIterator,
typename Predicate>
1391 inline typename eastl::iterator_traits<InputIterator>::difference_type
1392 count_if(InputIterator first, InputIterator last, Predicate predicate)
1394 typename eastl::iterator_traits<InputIterator>::difference_type result = 0;
1396 for(; first != last; ++first)
1398 if(predicate(*first))
1419 template <
typename InputIterator,
typename T>
1420 inline InputIterator
1421 find(InputIterator first, InputIterator last,
const T& value)
1423 while((first != last) && !(*first == value))
1431 template <
typename InputIterator,
typename T,
typename Predicate>
1432 inline InputIterator
1433 find(InputIterator first, InputIterator last,
const T& value, Predicate predicate)
1435 while((first != last) && !predicate(*first, value))
1457 template <
typename InputIterator,
typename Predicate>
1458 inline InputIterator
1459 find_if(InputIterator first, InputIterator last, Predicate predicate)
1461 while((first != last) && !predicate(*first))
1473 template <
typename InputIterator,
typename Predicate>
1474 inline InputIterator
1475 find_if_not(InputIterator first, InputIterator last, Predicate predicate)
1477 for(; first != last; ++first)
1479 if(!predicate(*first))
1508 template <
typename ForwardIterator1,
typename ForwardIterator2>
1511 ForwardIterator2 first2, ForwardIterator2 last2)
1513 for(; first1 != last1; ++first1)
1515 for(ForwardIterator2 i = first2; i != last2; ++i)
1543 template <
typename ForwardIterator1,
typename ForwardIterator2,
typename BinaryPredicate>
1546 ForwardIterator2 first2, ForwardIterator2 last2,
1547 BinaryPredicate predicate)
1549 for(; first1 != last1; ++first1)
1551 for(ForwardIterator2 i = first2; i != last2; ++i)
1553 if(predicate(*first1, *i))
1573 template <
class ForwardIterator1,
class ForwardIterator2>
1576 ForwardIterator2 first2, ForwardIterator2 last2)
1578 for(; first1 != last1; ++first1)
1601 template <
class ForwardIterator1,
class ForwardIterator2,
class BinaryPredicate>
1602 inline ForwardIterator1
1604 ForwardIterator2 first2, ForwardIterator2 last2,
1605 BinaryPredicate predicate)
1607 typedef typename eastl::iterator_traits<ForwardIterator1>::value_type value_type;
1609 for(; first1 != last1; ++first1)
1611 if(
eastl::find_if(first2, last2, eastl::bind1st<BinaryPredicate, value_type>(predicate, *first1)) == last2)
1619 template <
class B
idirectionalIterator1,
class ForwardIterator2>
1620 inline BidirectionalIterator1
1621 find_last_of(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
1622 ForwardIterator2 first2, ForwardIterator2 last2)
1624 if((first1 != last1) && (first2 != last2))
1626 BidirectionalIterator1 it1(last1);
1628 while((--it1 != first1) && (
eastl::find(first2, last2, *it1) == last2))
1631 if((it1 != first1) || (
eastl::find(first2, last2, *it1) != last2))
1639 template <
class B
idirectionalIterator1,
class ForwardIterator2,
class BinaryPredicate>
1640 BidirectionalIterator1
1641 find_last_of(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
1642 ForwardIterator2 first2, ForwardIterator2 last2,
1643 BinaryPredicate predicate)
1645 typedef typename eastl::iterator_traits<BidirectionalIterator1>::value_type value_type;
1647 if((first1 != last1) && (first2 != last2))
1649 BidirectionalIterator1 it1(last1);
1651 while((--it1 != first1) && (
eastl::find_if(first2, last2, eastl::bind1st<BinaryPredicate, value_type>(predicate, *it1)) == last2))
1654 if((it1 != first1) || (
eastl::find_if(first2, last2, eastl::bind1st<BinaryPredicate, value_type>(predicate, *it1)) != last2))
1662 template <
class B
idirectionalIterator1,
class ForwardIterator2>
1663 inline BidirectionalIterator1
1664 find_last_not_of(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
1665 ForwardIterator2 first2, ForwardIterator2 last2)
1667 if((first1 != last1) && (first2 != last2))
1669 BidirectionalIterator1 it1(last1);
1671 while((--it1 != first1) && (
eastl::find(first2, last2, *it1) != last2))
1674 if((it1 != first1) || (
eastl::find( first2, last2, *it1) == last2))
1682 template <
class B
idirectionalIterator1,
class ForwardIterator2,
class BinaryPredicate>
1683 inline BidirectionalIterator1
1684 find_last_not_of(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
1685 ForwardIterator2 first2, ForwardIterator2 last2,
1686 BinaryPredicate predicate)
1688 typedef typename eastl::iterator_traits<BidirectionalIterator1>::value_type value_type;
1690 if((first1 != last1) && (first2 != last2))
1692 BidirectionalIterator1 it1(last1);
1694 while((--it1 != first1) && (
eastl::find_if(first2, last2, eastl::bind1st<BinaryPredicate, value_type>(predicate, *it1)) != last2))
1697 if((it1 != first1) || (
eastl::find_if(first2, last2, eastl::bind1st<BinaryPredicate, value_type>(predicate, *it1))) != last2)
1721 template <
typename InputIterator,
typename Function>
1723 for_each(InputIterator first, InputIterator last, Function
function)
1725 for(; first != last; ++first)
1746 template <
typename InputIterator,
typename Size,
typename Function>
1747 EA_CPP14_CONSTEXPR
inline InputIterator
1750 for (Size i = 0; i < n; ++first, i++)
1764 template <
typename ForwardIterator,
typename Generator>
1766 generate(ForwardIterator first, ForwardIterator last, Generator generator)
1768 for(; first != last; ++first)
1769 *first = generator();
1781 template <
typename OutputIterator,
typename Size,
typename Generator>
1782 inline OutputIterator
1785 for(; n > 0; --n, ++first)
1786 *first = generator();
1807 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation>
1808 inline OutputIterator
1809 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation unaryOperation)
1811 for(; first != last; ++first, ++result)
1812 *result = unaryOperation(*first);
1833 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename BinaryOperation>
1834 inline OutputIterator
1835 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperation binaryOperation)
1837 for(; first1 != last1; ++first1, ++first2, ++result)
1838 *result = binaryOperation(*first1, *first2);
1855 template <
typename InputIterator1,
typename InputIterator2>
1856 EA_CPP14_CONSTEXPR
inline bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
1858 for(; first1 != last1; ++first1, ++first2)
1860 if(!(*first1 == *first2))
1915 template <
typename InputIterator1,
typename InputIterator2,
typename BinaryPredicate>
1917 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate predicate)
1919 for(; first1 != last1; ++first1, ++first2)
1921 if(!predicate(*first1, *first2))
1948 template <
typename InputIterator1,
typename InputIterator2>
1950 InputIterator2 first2, InputIterator2 last2)
1952 while((first1 != last1) && (first2 != last2) && (*first1 == *first2))
1957 return (first1 == last1) && (first2 == last2);
1963 template <
typename InputIterator1,
typename InputIterator2,
typename BinaryPredicate>
1965 InputIterator2 first2, InputIterator2 last2, BinaryPredicate predicate)
1967 while((first1 != last1) && (first2 != last2) && predicate(*first1, *first2))
1972 return (first1 == last1) && (first2 == last2);
1994 template <
typename InputIterator1,
typename InputIterator2>
1998 for(; (first1 != last1) && (first2 != last2); ++first1, ++first2)
2000 if(*first1 < *first2)
2002 if(*first2 < *first1)
2005 return (first1 == last1) && (first2 != last2);
2011 const ptrdiff_t n1(last1 - first1), n2(last2 - first2);
2012 const int result = __builtin_memcmp(first1, first2, (
size_t)
eastl::min_alt(n1, n2));
2013 return result ? (result < 0) : (n1 < n2);
2019 const ptrdiff_t n1(last1 - first1), n2(last2 - first2);
2020 const int result = __builtin_memcmp(first1, first2, (
size_t)
eastl::min_alt(n1, n2));
2021 return result ? (result < 0) : (n1 < n2);
2025 lexicographical_compare(
const unsigned char* first1,
const unsigned char* last1,
const unsigned char* first2,
const unsigned char* last2)
2027 const ptrdiff_t n1(last1 - first1), n2(last2 - first2);
2028 const int result = __builtin_memcmp(first1, first2, (
size_t)
eastl::min_alt(n1, n2));
2029 return result ? (result < 0) : (n1 < n2);
2033 lexicographical_compare(
unsigned char* first1,
unsigned char* last1,
unsigned char* first2,
unsigned char* last2)
2035 const ptrdiff_t n1(last1 - first1), n2(last2 - first2);
2036 const int result = __builtin_memcmp(first1, first2, (
size_t)
eastl::min_alt(n1, n2));
2037 return result ? (result < 0) : (n1 < n2);
2041 lexicographical_compare(
const signed char* first1,
const signed char* last1,
const signed char* first2,
const signed char* last2)
2043 const ptrdiff_t n1(last1 - first1), n2(last2 - first2);
2044 const int result = __builtin_memcmp(first1, first2, (
size_t)
eastl::min_alt(n1, n2));
2045 return result ? (result < 0) : (n1 < n2);
2051 const ptrdiff_t n1(last1 - first1), n2(last2 - first2);
2052 const int result = __builtin_memcmp(first1, first2, (
size_t)
eastl::min_alt(n1, n2));
2053 return result ? (result < 0) : (n1 < n2);
2056 #if defined(_MSC_VER)
2100 template <
typename InputIterator1,
typename InputIterator2,
typename Compare>
2103 InputIterator2 first2, InputIterator2 last2, Compare compare)
2105 for(; (first1 != last1) && (first2 != last2); ++first1, ++first2)
2107 if(compare(*first1, *first2))
2109 if(compare(*first2, *first1))
2112 return (first1 == last1) && (first2 != last2);
2130 template <
class InputIterator1,
class InputIterator2>
2133 InputIterator2 first2)
2135 while((first1 != last1) && (*first1 == *first2))
2159 template <
class InputIterator1,
class InputIterator2,
class BinaryPredicate>
2162 InputIterator2 first2,
2163 BinaryPredicate predicate)
2165 while((first1 != last1) && predicate(*first1, *first2))
2193 template <
typename ForwardIterator,
typename T>
2195 lower_bound(ForwardIterator first, ForwardIterator last,
const T& value)
2197 typedef typename eastl::iterator_traits<ForwardIterator>::difference_type DifferenceType;
2199 DifferenceType d = eastl::distance(first, last);
2203 ForwardIterator i = first;
2204 DifferenceType d2 = d >> 1;
2206 eastl::advance(i, d2);
2241 template <
typename ForwardIterator,
typename T,
typename Compare>
2243 lower_bound(ForwardIterator first, ForwardIterator last,
const T& value, Compare compare)
2245 typedef typename eastl::iterator_traits<ForwardIterator>::difference_type DifferenceType;
2247 DifferenceType d = eastl::distance(first, last);
2251 ForwardIterator i = first;
2252 DifferenceType d2 = d >> 1;
2254 eastl::advance(i, d2);
2256 if(compare(*i, value))
2284 template <
typename ForwardIterator,
typename T>
2286 upper_bound(ForwardIterator first, ForwardIterator last,
const T& value)
2288 typedef typename eastl::iterator_traits<ForwardIterator>::difference_type DifferenceType;
2290 DifferenceType len = eastl::distance(first, last);
2294 ForwardIterator i = first;
2295 DifferenceType len2 = len >> 1;
2297 eastl::advance(i, len2);
2330 template <
typename ForwardIterator,
typename T,
typename Compare>
2332 upper_bound(ForwardIterator first, ForwardIterator last,
const T& value, Compare compare)
2334 typedef typename eastl::iterator_traits<ForwardIterator>::difference_type DifferenceType;
2336 DifferenceType len = eastl::distance(first, last);
2340 ForwardIterator i = first;
2341 DifferenceType len2 = len >> 1;
2343 eastl::advance(i, len2);
2345 if(!compare(value, *i))
2368 template <
typename ForwardIterator,
typename T>
2369 pair<ForwardIterator, ForwardIterator>
2370 equal_range(ForwardIterator first, ForwardIterator last,
const T& value)
2373 typedef typename eastl::iterator_traits<ForwardIterator>::difference_type DifferenceType;
2375 DifferenceType d = eastl::distance(first, last);
2379 ForwardIterator i(first);
2380 DifferenceType d2 = d >> 1;
2382 eastl::advance(i, d2);
2386 EASTL_VALIDATE_COMPARE(!(value < *i));
2392 EASTL_VALIDATE_COMPARE(!(*i < value));
2398 ForwardIterator j(i);
2404 return ResultType(first, first);
2416 template <
typename ForwardIterator,
typename T,
typename Compare>
2417 pair<ForwardIterator, ForwardIterator>
2418 equal_range(ForwardIterator first, ForwardIterator last,
const T& value, Compare compare)
2421 typedef typename eastl::iterator_traits<ForwardIterator>::difference_type DifferenceType;
2423 DifferenceType d = eastl::distance(first, last);
2427 ForwardIterator i(first);
2428 DifferenceType d2 = d >> 1;
2430 eastl::advance(i, d2);
2432 if(compare(*i, value))
2434 EASTL_VALIDATE_COMPARE(!compare(value, *i));
2438 else if(compare(value, *i))
2440 EASTL_VALIDATE_COMPARE(!compare(*i, value));
2446 ForwardIterator j(i);
2452 return ResultType(first, first);
2466 template <
typename ForwardIterator,
typename T>
2468 replace(ForwardIterator first, ForwardIterator last,
const T& old_value,
const T& new_value)
2470 for(; first != last; ++first)
2472 if(*first == old_value)
2488 template <
typename ForwardIterator,
typename Predicate,
typename T>
2490 replace_if(ForwardIterator first, ForwardIterator last, Predicate predicate,
const T& new_value)
2492 for(; first != last; ++first)
2494 if(predicate(*first))
2512 template <
typename InputIterator,
typename OutputIterator,
typename T>
2513 inline OutputIterator
2514 remove_copy(InputIterator first, InputIterator last, OutputIterator result,
const T& value)
2516 for(; first != last; ++first)
2518 if(!(*first == value))
2540 template <
typename InputIterator,
typename OutputIterator,
typename Predicate>
2541 inline OutputIterator
2542 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate predicate)
2544 for(; first != last; ++first)
2546 if(!predicate(*first))
2579 template <
typename ForwardIterator,
typename T>
2580 inline ForwardIterator
2581 remove(ForwardIterator first, ForwardIterator last,
const T& value)
2586 ForwardIterator i(first);
2616 template <
typename ForwardIterator,
typename Predicate>
2617 inline ForwardIterator
2618 remove_if(ForwardIterator first, ForwardIterator last, Predicate predicate)
2623 ForwardIterator i(first);
2624 return eastl::remove_copy_if<ForwardIterator, ForwardIterator, Predicate>(++i, last, first, predicate);
2645 template <
typename InputIterator,
typename OutputIterator,
typename T>
2646 inline OutputIterator
2647 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
const T& old_value,
const T& new_value)
2649 for(; first != last; ++first, ++result)
2650 *result = (*first == old_value) ? new_value : *first;
2670 template <
typename InputIterator,
typename OutputIterator,
typename Predicate,
typename T>
2671 inline OutputIterator
2672 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate predicate,
const T& new_value)
2674 for(; first != last; ++first, ++result)
2675 *result = predicate(*first) ? new_value : *first;
2687 template <
typename B
idirectionalIterator>
2688 inline void reverse_impl(BidirectionalIterator first, BidirectionalIterator last, EASTL_ITC_NS::bidirectional_iterator_tag)
2690 for(; (first != last) && (first != --last); ++first)
2694 template <
typename RandomAccessIterator>
2695 inline void reverse_impl(RandomAccessIterator first, RandomAccessIterator last, EASTL_ITC_NS::random_access_iterator_tag)
2699 for(; first < --last; ++first)
2713 template <
typename B
idirectionalIterator>
2714 inline void reverse(BidirectionalIterator first, BidirectionalIterator last)
2716 typedef typename eastl::iterator_traits<BidirectionalIterator>::iterator_category IC;
2717 eastl::reverse_impl(first, last, IC());
2738 template <
typename B
idirectionalIterator,
typename OutputIterator>
2739 inline OutputIterator
2740 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result)
2742 for(; first != last; ++result)
2763 template <
typename ForwardIterator1,
typename ForwardIterator2>
2765 search(ForwardIterator1 first1, ForwardIterator1 last1,
2766 ForwardIterator2 first2, ForwardIterator2 last2)
2772 ForwardIterator2 temp2(first2);
2777 ForwardIterator1 cur1(first1);
2778 ForwardIterator2 p2;
2780 while(first1 != last1)
2783 while((first1 != last1) && !(*first1 == *first2))
2858 template <
typename ForwardIterator1,
typename ForwardIterator2,
typename BinaryPredicate>
2860 search(ForwardIterator1 first1, ForwardIterator1 last1,
2861 ForwardIterator2 first2, ForwardIterator2 last2,
2862 BinaryPredicate predicate)
2864 typedef typename eastl::iterator_traits<ForwardIterator1>::difference_type difference_type_1;
2865 typedef typename eastl::iterator_traits<ForwardIterator2>::difference_type difference_type_2;
2867 difference_type_2 d2 = eastl::distance(first2, last2);
2871 ForwardIterator1 i(first1);
2872 eastl::advance(i, d2);
2874 for(difference_type_1 d1 = eastl::distance(first1, last1); d1 >= d2; --d1)
2876 if(eastl::equal<ForwardIterator1, ForwardIterator2, BinaryPredicate>(first1, i, first2, predicate))
2893 template <
typename ForwardIterator,
typename Size,
typename T>
2895 search_n_impl(ForwardIterator first, ForwardIterator last, Size
count,
const T& value, EASTL_ITC_NS::forward_iterator_tag)
2900 Size d1 = (Size)eastl::distance(first, last);
2905 for(; d1 >=
count; ++first, --d1)
2907 ForwardIterator i(first);
2909 for(Size n = 0; n <
count; ++n, ++i, --d1)
2922 template <
typename RandomAccessIterator,
typename Size,
typename T>
inline
2923 RandomAccessIterator
2924 search_n_impl(RandomAccessIterator first, RandomAccessIterator last, Size
count,
const T& value, EASTL_ITC_NS::random_access_iterator_tag)
2930 else if(last > first)
2932 RandomAccessIterator lookAhead;
2933 RandomAccessIterator backTrack;
2935 Size skipOffset = (
count - 1);
2936 Size tailSize = (Size)(last - first);
2940 for(lookAhead = first + skipOffset; tailSize >=
count; lookAhead +=
count)
2944 if(*lookAhead == value)
2946 remainder = skipOffset;
2948 for(backTrack = lookAhead - 1; *backTrack == value; --backTrack)
2950 if(--remainder == 0)
2951 return (lookAhead - skipOffset);
2954 if(remainder <= tailSize)
2956 prevRemainder = remainder;
2958 while(*(++lookAhead) == value)
2960 if(--remainder == 0)
2961 return (backTrack + 1);
2963 tailSize -= (prevRemainder - remainder);
2986 template <
typename ForwardIterator,
typename Size,
typename T>
2988 search_n(ForwardIterator first, ForwardIterator last, Size
count,
const T& value)
2990 typedef typename eastl::iterator_traits<ForwardIterator>::iterator_category IC;
2991 return eastl::search_n_impl(first, last,
count, value, IC());
3016 template <
typename ForwardIterator,
typename T>
3021 ForwardIterator i(eastl::lower_bound<ForwardIterator, T>(first, last, value));
3022 return ((i != last) && !(value < *i));
3036 template <
typename ForwardIterator,
typename T,
typename Compare>
3038 binary_search(ForwardIterator first, ForwardIterator last,
const T& value, Compare compare)
3041 ForwardIterator i(eastl::lower_bound<ForwardIterator, T, Compare>(first, last, value, compare));
3042 return ((i != last) && !compare(value, *i));
3054 template <
typename ForwardIterator,
typename T>
3055 inline ForwardIterator
3059 ForwardIterator i(eastl::lower_bound<ForwardIterator, T>(first, last, value));
3060 if((i != last) && !(value < *i))
3074 template <
typename ForwardIterator,
typename T,
typename Compare>
3075 inline ForwardIterator
3076 binary_search_i(ForwardIterator first, ForwardIterator last,
const T& value, Compare compare)
3079 ForwardIterator i(eastl::lower_bound<ForwardIterator, T, Compare>(first, last, value, compare));
3080 if((i != last) && !compare(value, *i))
3108 template <
typename ForwardIterator>
3109 ForwardIterator
unique(ForwardIterator first, ForwardIterator last)
3111 first = eastl::adjacent_find<ForwardIterator>(first, last);
3115 ForwardIterator dest(first);
3117 for(++first; first != last; ++first)
3119 if(!(*dest == *first))
3145 template <
typename ForwardIterator,
typename BinaryPredicate>
3146 ForwardIterator
unique(ForwardIterator first, ForwardIterator last, BinaryPredicate predicate)
3148 first = eastl::adjacent_find<ForwardIterator, BinaryPredicate>(first, last, predicate);
3152 ForwardIterator dest(first);
3154 for(++first; first != last; ++first)
3156 if(!predicate(*dest, *first))
3173 template <
typename ForwardIterator1,
typename ForwardIterator2>
3175 find_end_impl(ForwardIterator1 first1, ForwardIterator1 last1,
3176 ForwardIterator2 first2, ForwardIterator2 last2,
3177 EASTL_ITC_NS::forward_iterator_tag, EASTL_ITC_NS::forward_iterator_tag)
3181 for(ForwardIterator1 result(last1); ; )
3183 const ForwardIterator1 resultNext(
eastl::search(first1, last1, first2, last2));
3185 if(resultNext != last1)
3187 first1 = result = resultNext;
3197 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2>
3198 BidirectionalIterator1
3199 find_end_impl(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
3200 BidirectionalIterator2 first2, BidirectionalIterator2 last2,
3201 EASTL_ITC_NS::bidirectional_iterator_tag, EASTL_ITC_NS::bidirectional_iterator_tag)
3206 reverse_iterator1 rresult(
eastl::search(reverse_iterator1(last1), reverse_iterator1(first1),
3207 reverse_iterator2(last2), reverse_iterator2(first2)));
3208 if(rresult.base() != first1)
3210 BidirectionalIterator1 result(rresult.base());
3212 eastl::advance(result, -eastl::distance(first2, last2));
3229 template <
typename ForwardIterator1,
typename ForwardIterator2>
3230 inline ForwardIterator1
3231 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
3232 ForwardIterator2 first2, ForwardIterator2 last2)
3234 typedef typename eastl::iterator_traits<ForwardIterator1>::iterator_category IC1;
3235 typedef typename eastl::iterator_traits<ForwardIterator2>::iterator_category IC2;
3237 return eastl::find_end_impl(first1, last1, first2, last2, IC1(), IC2());
3245 template <
typename ForwardIterator1,
typename ForwardIterator2,
typename BinaryPredicate>
3247 find_end_impl(ForwardIterator1 first1, ForwardIterator1 last1,
3248 ForwardIterator2 first2, ForwardIterator2 last2,
3249 BinaryPredicate predicate,
3250 EASTL_ITC_NS::forward_iterator_tag, EASTL_ITC_NS::forward_iterator_tag)
3254 for(ForwardIterator1 result = last1; ; )
3256 const ForwardIterator1 resultNext(eastl::search<ForwardIterator1, ForwardIterator2, BinaryPredicate>(first1, last1, first2, last2, predicate));
3258 if(resultNext != last1)
3260 first1 = result = resultNext;
3270 template <
typename B
idirectionalIterator1,
typename B
idirectionalIterator2,
typename BinaryPredicate>
3271 BidirectionalIterator1
3272 find_end_impl(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
3273 BidirectionalIterator2 first2, BidirectionalIterator2 last2,
3274 BinaryPredicate predicate,
3275 EASTL_ITC_NS::bidirectional_iterator_tag, EASTL_ITC_NS::bidirectional_iterator_tag)
3280 reverse_iterator1 rresult(eastl::search<reverse_iterator1, reverse_iterator2, BinaryPredicate>
3281 (reverse_iterator1(last1), reverse_iterator1(first1),
3282 reverse_iterator2(last2), reverse_iterator2(first2),
3284 if(rresult.base() != first1)
3286 BidirectionalIterator1 result(rresult.base());
3287 eastl::advance(result, -eastl::distance(first2, last2));
3306 template <
typename ForwardIterator1,
typename ForwardIterator2,
typename BinaryPredicate>
3307 inline ForwardIterator1
3308 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
3309 ForwardIterator2 first2, ForwardIterator2 last2,
3310 BinaryPredicate predicate)
3312 typedef typename eastl::iterator_traits<ForwardIterator1>::iterator_category IC1;
3313 typedef typename eastl::iterator_traits<ForwardIterator2>::iterator_category IC2;
3315 return eastl::find_end_impl<ForwardIterator1, ForwardIterator2, BinaryPredicate>
3316 (first1, last1, first2, last2, predicate, IC1(), IC2());
3336 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
3338 InputIterator2 first2, InputIterator2 last2,
3339 OutputIterator result)
3341 while((first1 != last1) && (first2 != last2))
3343 if(*first1 < *first2)
3349 else if(*first2 < *first1)
3362 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Compare>
3363 OutputIterator
set_difference(InputIterator1 first1, InputIterator1 last1,
3364 InputIterator2 first2, InputIterator2 last2,
3365 OutputIterator result, Compare compare)
3367 while((first1 != last1) && (first2 != last2))
3369 if(compare(*first1, *first2))
3371 EASTL_VALIDATE_COMPARE(!compare(*first2, *first1));
3376 else if(compare(*first2, *first1))
3378 EASTL_VALIDATE_COMPARE(!compare(*first1, *first2));
3412 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Compare>
3414 InputIterator2 first2, InputIterator2 last2,
3415 OutputIterator result1, OutputIterator result2, Compare compare)
3417 while ((first1 != last1) && (first2 != last2))
3419 if (compare(*first1, *first2))
3421 EASTL_VALIDATE_COMPARE(!compare(*first2, *first1));
3422 *result1++ = *first1++;
3424 else if (compare(*first2, *first1))
3426 EASTL_VALIDATE_COMPARE(!compare(*first1, *first2));
3427 *result2++ = *first2++;
3444 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
3446 InputIterator2 first2, InputIterator2 last2,
3447 OutputIterator result1, OutputIterator result2)
3470 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
3472 InputIterator2 first2, InputIterator2 last2,
3473 OutputIterator result)
3475 while((first1 != last1) && (first2 != last2))
3477 if(*first1 < *first2)
3483 else if(*first2 < *first1)
3500 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Compare>
3502 InputIterator2 first2, InputIterator2 last2,
3503 OutputIterator result, Compare compare)
3505 while((first1 != last1) && (first2 != last2))
3507 if(compare(*first1, *first2))
3509 EASTL_VALIDATE_COMPARE(!compare(*first2, *first1));
3514 else if(compare(*first2, *first1))
3516 EASTL_VALIDATE_COMPARE(!compare(*first1, *first2));
3550 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
3552 InputIterator2 first2, InputIterator2 last2,
3553 OutputIterator result)
3555 while((first1 != last1) && (first2 != last2))
3557 if(*first1 < *first2)
3559 else if(*first2 < *first1)
3574 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Compare>
3575 OutputIterator
set_intersection(InputIterator1 first1, InputIterator1 last1,
3576 InputIterator2 first2, InputIterator2 last2,
3577 OutputIterator result, Compare compare)
3579 while((first1 != last1) && (first2 != last2))
3581 if(compare(*first1, *first2))
3583 EASTL_VALIDATE_COMPARE(!compare(*first2, *first1));
3586 else if(compare(*first2, *first1))
3588 EASTL_VALIDATE_COMPARE(!compare(*first1, *first2));
3623 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator>
3624 OutputIterator
set_union(InputIterator1 first1, InputIterator1 last1,
3625 InputIterator2 first2, InputIterator2 last2,
3626 OutputIterator result)
3628 while((first1 != last1) && (first2 != last2))
3630 if(*first1 < *first2)
3635 else if(*first2 < *first1)
3653 template <
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Compare>
3654 OutputIterator
set_union(InputIterator1 first1, InputIterator1 last1,
3655 InputIterator2 first2, InputIterator2 last2,
3656 OutputIterator result, Compare compare)
3658 while((first1 != last1) && (first2 != last2))
3660 if(compare(*first1, *first2))
3662 EASTL_VALIDATE_COMPARE(!compare(*first2, *first1));
3666 else if(compare(*first2, *first1))
3668 EASTL_VALIDATE_COMPARE(!compare(*first1, *first2));
3702 template <
typename InputIterator1,
typename InputIterator2,
3703 typename OutputIterator1,
typename OutputIterator2,
typename OutputIterator3,
typename Compare>
3705 InputIterator2 first2, InputIterator2 last2,
3706 OutputIterator1 result1, OutputIterator2 result2, OutputIterator3 result3, Compare compare)
3708 while ((first1 != last1) && (first2 != last2))
3710 if (compare(*first1, *first2))
3712 EASTL_VALIDATE_COMPARE(!compare(*first2, *first1));
3713 *result1++ = *first1++;
3715 else if (compare(*first2, *first1))
3717 EASTL_VALIDATE_COMPARE(!compare(*first1, *first2));
3718 *result2++ = *first2++;
3722 *result3++ = *first1++;
3737 template <
typename InputIterator1,
typename InputIterator2,
3738 typename OutputIterator1,
typename OutputIterator2,
typename OutputIterator3>
3739 OutputIterator3
set_decomposition(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
3740 OutputIterator1 result1, OutputIterator2 result2, OutputIterator3 result3)
3748 template<
typename ForwardIterator1,
typename ForwardIterator2>
3749 bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
3751 typedef typename eastl::iterator_traits<ForwardIterator1>::difference_type difference_type;
3754 while((first1 != last1) && (*first1 == *first2))
3762 const difference_type first1Size = eastl::distance(first1, last1);
3763 ForwardIterator2 last2 = first2;
3764 eastl::advance(last2, first1Size);
3766 for(ForwardIterator1 i = first1; i != last1; ++i)
3770 const difference_type c =
eastl::count(first2, last2, *i);
3783 template<
typename ForwardIterator1,
typename ForwardIterator2,
class BinaryPredicate>
3784 bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate predicate)
3786 typedef typename eastl::iterator_traits<ForwardIterator1>::difference_type difference_type;
3789 while((first1 != last1) && predicate(*first1, *first2))
3797 const difference_type first1Size = eastl::distance(first1, last1);
3798 ForwardIterator2 last2 = first2;
3799 eastl::advance(last2, first1Size);
3801 for(ForwardIterator1 i = first1; i != last1; ++i)
3805 const difference_type c =
eastl::count(first2, last2, *i, predicate);
3807 if((c == 0) || (c !=
eastl::count(i, last1, *i, predicate)))
3843 template<
typename B
idirectionalIterator,
typename Compare>
3844 bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare compare)
3848 BidirectionalIterator i = last;
3854 BidirectionalIterator ii(i), j;
3856 if(compare(*--i, *ii))
3859 while(!compare(*i, *--j))
3878 template<
typename B
idirectionalIterator>
3879 bool next_permutation(BidirectionalIterator first, BidirectionalIterator last)
3881 typedef typename eastl::iterator_traits<BidirectionalIterator>::value_type value_type;
3926 template<
typename ForwardIterator>
3927 ForwardIterator rotate_general_impl(ForwardIterator first, ForwardIterator middle, ForwardIterator last)
3931 ForwardIterator current = middle;
3934 swap(*first++, *current++);
3938 }
while(current != last);
3940 ForwardIterator result = first;
3943 while(current != last)
3945 swap(*first++, *current++);
3949 else if(current == last)
3957 template <
typename ForwardIterator>
3958 ForwardIterator move_rotate_left_by_one(ForwardIterator first, ForwardIterator last)
3960 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
3963 ForwardIterator result =
eastl::move(eastl::next(first), last, first);
3970 template <
typename B
idirectionalIterator>
3971 BidirectionalIterator move_rotate_right_by_one(BidirectionalIterator first, BidirectionalIterator last)
3973 typedef typename eastl::iterator_traits<BidirectionalIterator>::value_type value_type;
3975 BidirectionalIterator beforeLast = eastl::prev(last);
3983 template <
typename ,
bool >
3986 template <
typename ForwardIterator>
3987 static ForwardIterator rotate_impl(ForwardIterator first, ForwardIterator middle, ForwardIterator last)
3988 {
return Internal::rotate_general_impl(first, middle, last); }
3994 template <
typename ForwardIterator>
3995 static ForwardIterator rotate_impl(ForwardIterator first, ForwardIterator middle, ForwardIterator last)
3997 if(eastl::next(first) == middle)
3998 return Internal::move_rotate_left_by_one(first, last);
3999 return Internal::rotate_general_impl(first, middle, last);
4006 template <
typename B
idirectionalIterator>
4007 static BidirectionalIterator rotate_impl(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last)
4008 {
return Internal::rotate_general_impl(first, middle, last); }
4053 template <
typename B
idirectionalIterator>
4054 static BidirectionalIterator rotate_impl(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last)
4056 if(eastl::next(first) == middle)
4057 return Internal::move_rotate_left_by_one(first, last);
4058 if(eastl::next(middle) == last)
4059 return Internal::move_rotate_right_by_one(first, last);
4060 return Internal::rotate_general_impl(first, middle, last);
4064 template <
typename Integer>
4065 inline Integer greatest_common_divisor(Integer x, Integer y)
4068 Integer t = (x % y);
4082 template <
typename RandomAccessIterator>
4083 static RandomAccessIterator rotate_impl(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last)
4085 typedef typename iterator_traits<RandomAccessIterator>::difference_type difference_type;
4086 typedef typename iterator_traits<RandomAccessIterator>::value_type value_type;
4088 const difference_type m1 = (middle - first);
4089 const difference_type m2 = (last - middle);
4090 const difference_type g = Internal::greatest_common_divisor(m1, m2);
4093 for(RandomAccessIterator p = first + g; p != first;)
4096 RandomAccessIterator p1 = p;
4097 RandomAccessIterator p2 = p + m1;
4102 const difference_type d = (last - p2);
4107 p2 = first + (m1 - d);
4126 template <
typename RandomAccessIterator>
4127 static RandomAccessIterator rotate_impl(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last)
4129 if(eastl::next(first) == middle)
4130 return Internal::move_rotate_left_by_one(first, last);
4131 if(eastl::next(middle) == last)
4132 return Internal::move_rotate_right_by_one(first, last);
4133 if((last - first) < 32)
4134 return Internal::rotate_general_impl(first, middle, last);
4142 template <
typename ForwardIterator>
4143 ForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last)
4149 typedef typename eastl::iterator_traits<ForwardIterator>::iterator_category IC;
4150 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
4155 ::rotate_impl(first, middle, last);
4172 template <
typename ForwardIterator,
typename OutputIterator>
4173 OutputIterator
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result)
4186 template <
class T,
class Compare>
4187 EA_CONSTEXPR
const T&
clamp(
const T& v,
const T& lo,
const T& hi, Compare comp)
4190 return [&] { EASTL_ASSERT(!comp(hi, lo)); }(),
4191 comp(v, lo) ? lo : comp(hi, v) ? hi : v;
4195 EA_CONSTEXPR
const T&
clamp(
const T& v,
const T& lo,
const T& hi)
Definition: iterator.h:224
Definition: initializer_list.h:38
EA Standard Template Library.
Definition: algorithm.h:288
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)
Definition: algorithm.h:1347
void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator &&rng)
Definition: algorithm.h:1064
void replace_if(ForwardIterator first, ForwardIterator last, Predicate predicate, const T &new_value)
Definition: algorithm.h:2490
bool identical(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Definition: algorithm.h:1949
OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result)
Definition: algorithm.h:4173
ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T &value)
Definition: algorithm.h:2581
OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
Definition: algorithm.h:3337
bool all_of(InputIterator first, InputIterator last, Predicate p)
Definition: algorithm.h:909
OutputIterator copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate predicate)
Definition: algorithm.h:1172
InputIterator find(InputIterator first, InputIterator last, const T &value)
Definition: algorithm.h:1421
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T &value)
Definition: algorithm.h:2286
T max(std::initializer_list< T > ilist)
Definition: algorithm.h:652
OutputIterator3 set_decomposition(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator1 result1, OutputIterator2 result2, OutputIterator3 result3, Compare compare)
Definition: algorithm.h:3704
pair< ForwardIterator, ForwardIterator > equal_range(ForwardIterator first, ForwardIterator last, const T &value)
Definition: algorithm.h:2370
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
Definition: copy_help.h:191
eastl::iterator_traits< InputIterator >::difference_type count_if(InputIterator first, InputIterator last, Predicate predicate)
Definition: algorithm.h:1392
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare compare)
Definition: algorithm.h:3844
bool binary_search(ForwardIterator first, ForwardIterator last, const T &value)
Definition: algorithm.h:3018
eastl::pair< ForwardIterator, ForwardIterator > minmax_element(ForwardIterator first, ForwardIterator last, Compare compare)
Definition: algorithm.h:678
OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T &value)
Definition: algorithm.h:2514
OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T &old_value, const T &new_value)
Definition: algorithm.h:2647
eastl::pair< const T &, const T & > minmax(const T &a, const T &b)
Definition: algorithm.h:772
InputIterator find_if(InputIterator first, InputIterator last, Predicate predicate)
Definition: algorithm.h:1459
OutputIterator move(InputIterator first, InputIterator last, OutputIterator result)
Definition: copy_help.h:170
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last)
Definition: algorithm.h:962
OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation unaryOperation)
Definition: algorithm.h:1809
void reverse(BidirectionalIterator first, BidirectionalIterator last)
Definition: algorithm.h:2714
OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
Definition: algorithm.h:3624
OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate predicate)
Definition: algorithm.h:2542
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate predicate)
Definition: algorithm.h:2618
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T &value)
Definition: algorithm.h:2195
void iter_swap(ForwardIterator1 a, ForwardIterator2 b)
Definition: utility.h:237
ForwardIterator max_element(ForwardIterator first, ForwardIterator last)
Definition: algorithm.h:368
ForwardIterator1 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2)
Definition: algorithm.h:1510
OutputIterator replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate predicate, const T &new_value)
Definition: algorithm.h:2672
void shuffle(RandomAccessIterator first, RandomAccessIterator last, UniformRandomNumberGenerator &&urng)
Definition: algorithm.h:1028
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value)
Definition: algorithm.h:3056
OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result)
Definition: algorithm.h:2740
EA_CPP14_CONSTEXPR bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
Definition: algorithm.h:1856
void generate(ForwardIterator first, ForwardIterator last, Generator generator)
Definition: algorithm.h:1766
void set_difference_2(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result1, OutputIterator result2, Compare compare)
Definition: algorithm.h:3413
EA_CPP14_CONSTEXPR InputIterator for_each_n(InputIterator first, Size n, Function function)
Definition: algorithm.h:1748
EA_CONSTEXPR eastl::enable_if< eastl::is_scalar< T >::value, T >::type max_alt(T a, T b)
Definition: algorithm.h:584
EA_CONSTEXPR const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition: algorithm.h:4187
bool none_of(InputIterator first, InputIterator last, Predicate p)
Definition: algorithm.h:941
ForwardIterator unique(ForwardIterator first, ForwardIterator last)
Definition: algorithm.h:3109
void replace(ForwardIterator first, ForwardIterator last, const T &old_value, const T &new_value)
Definition: algorithm.h:2468
InputIterator find_if_not(InputIterator first, InputIterator last, Predicate predicate)
Definition: algorithm.h:1475
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
Definition: algorithm.h:3749
ForwardIterator1 find_first_not_of(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2)
Definition: algorithm.h:1575
eastl::pair< InputIterator1, InputIterator2 > mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
Definition: algorithm.h:2132
EA_CPP14_CONSTEXPR pair< typename eastl::remove_reference_wrapper< typename eastl::decay< T1 >::type >::type, typename eastl::remove_reference_wrapper< typename eastl::decay< T2 >::type >::type > make_pair(T1 &&a, T2 &&b)
Definition: utility.h:694
OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
Definition: algorithm.h:3471
ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2)
Definition: algorithm.h:3231
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Definition: algorithm.h:1996
T min(std::initializer_list< T > ilist)
Definition: algorithm.h:635
BidirectionalIterator2 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
Definition: algorithm.h:1304
OutputIterator move_n_impl(InputIterator first, Size n, OutputIterator result, EASTL_ITC_NS::input_iterator_tag)
Definition: algorithm.h:1108
OutputIterator copy_n_impl(InputIterator first, Size n, OutputIterator result, EASTL_ITC_NS::input_iterator_tag)
Definition: algorithm.h:1142
Function for_each(InputIterator first, InputIterator last, Function function)
Definition: algorithm.h:1723
ForwardIterator min_element(ForwardIterator first, ForwardIterator last)
Definition: algorithm.h:304
ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2)
Definition: algorithm.h:2765
ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T &value)
Definition: algorithm.h:2988
bool any_of(InputIterator first, InputIterator last, Predicate p)
Definition: algorithm.h:925
EA_CONSTEXPR eastl::enable_if< eastl::is_scalar< T >::value, T >::type min_alt(T a, T b)
Definition: algorithm.h:472
OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
Definition: algorithm.h:3551
BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 resultEnd)
Definition: algorithm.h:1325
const T & median(const T &a, const T &b, const T &c)
Definition: algorithm.h:833
OutputIterator generate_n(OutputIterator first, Size n, Generator generator)
Definition: algorithm.h:1783
Definition: algorithm.h:3985
Definition: iterator.h:76
Definition: type_traits.h:442
Definition: iterator.h:75
Definition: iterator.h:583
Definition: type_pod.h:102
Definition: type_compound.h:258
Definition: type_traits.h:604
Definition: type_compound.h:562
Definition: type_pod.h:708
less<T>
Definition: functional_base.h:202
Definition: algorithm.h:1190
Definition: utility.h:371
Definition: iterator.h:77