29 #ifndef __ETL_ALGORITHM__
30 #define __ETL_ALGORITHM__
50 template <
typename TIterator,
typename TCompare>
53 TIterator minimum =
begin;
54 TIterator maximum =
begin;
58 if (compare(*begin, *minimum))
63 if (compare(*maximum, *begin))
71 return std::pair<TIterator, TIterator>(minimum, maximum);
79 template <
typename TIterator>
82 typedef typename std::iterator_traits<TIterator>::value_type value_t;
93 std::pair<const T&, const T&>
minmax(
const T& a,
const T& b)
95 return (b < a) ? std::pair<const T&, const T&>(b, a) : std::pair<const T&, const T&>(a, b);
103 template <
typename T,
typename TCompare>
104 std::pair<const T&, const T&>
minmax(
const T& a,
const T& b, TCompare compare)
106 return compare(b, a) ? std::pair<const T&, const T&>(b, a) : std::pair<const T&, const T&>(a, b);
114 template <
typename TIterator>
121 while (++next != end)
140 template <
typename TIterator,
typename TCompare>
147 while (++next != end)
149 if (compare(*next, *begin))
166 template<
class TIterator>
177 template<
class TIterator,
class TCompare>
188 template <
typename TInputIterator,
typename Size,
typename TOutputIterator>
189 TOutputIterator
copy_n(TInputIterator
begin, Size count, TOutputIterator result)
193 for (Size i = 0; i < count; ++i)
195 *result++ = *begin++;
207 template <
typename TIterator,
typename TOutputIterator,
typename TUnaryPredicate>
208 TOutputIterator
copy_if(TIterator
begin, TIterator
end, TOutputIterator out, TUnaryPredicate predicate)
212 if (predicate(*begin))
228 template <
typename TIterator,
typename TUnaryPredicate>
233 if (!predicate(*begin))
249 template <
typename TIterator,
typename TUnaryPredicate >
260 template <
typename TIterator,
typename TUnaryPredicate >
263 return std::find_if(begin, end, predicate) !=
end;
271 template <
typename TIterator,
typename TUnaryPredicate >
274 return std::find_if(begin, end, predicate) ==
end;
282 template <
typename TIterator1,
typename TIterator2>
287 TIterator2 end2 = begin2;
289 std::advance(end2, std::distance(begin1, end1));
291 for (TIterator1 i = begin1; i != end1; ++i)
293 if (i == std::find(begin1, i, *i))
295 size_t n = std::count(begin2, end2, *i);
297 if (n == 0 || std::count(i, end1, *i) != n)
313 template <
typename TIterator1,
typename TIterator2>
314 bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TIterator2 end2)
318 for (TIterator1 i = begin1; i != end1; ++i)
320 if (i == std::find(begin1, i, *i))
322 size_t n = std::count(begin2, end2, *i);
324 if (n == 0 || std::count(i, end1, *i) != n)
340 template <
typename TIterator1,
typename TIterator2,
typename TBinaryPredicate>
341 bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TBinaryPredicate predicate)
345 TIterator2 end2 = begin2;
347 std::advance(end2, std::distance(begin1, end1));
349 for (TIterator1 i = begin1; i != end1; ++i)
351 if (i == std::find_if(begin1, i, std::bind1st(predicate, *i)))
353 size_t n = std::count(begin2, end2, *i);
355 if (n == 0 || std::count(i, end1, *i) != n)
371 template <
typename TIterator1,
typename TIterator2,
typename TBinaryPredicate>
372 bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TIterator2 end2, TBinaryPredicate predicate)
376 for (TIterator1 i = begin1; i != end1; ++i)
378 if (i == std::find_if(begin1, i, std::bind1st(predicate, *i)))
380 size_t n = std::count(begin2, end2, *i);
382 if (n == 0 || std::count(i, end1, *i) != n)
398 template <
typename TIterator,
typename TUnaryPredicate>
403 if (!predicate(*begin++))
411 if (predicate(*begin++))
425 template <
class TIterator,
class TUnaryPredicate>
430 if (!predicate(*begin))
447 template <
typename TSource,
typename TDestinationTrue,
typename TDestinationFalse,
typename TUnaryPredicate>
450 TDestinationTrue destination_true,
451 TDestinationFalse destination_false,
452 TUnaryPredicate predicate)
456 if (predicate(*begin))
458 *destination_true++ = *begin++;
462 *destination_false++ = *begin++;
466 return std::pair<TDestinationTrue, TDestinationFalse>(destination_true, destination_false);
std::pair< TDestinationTrue, TDestinationFalse > partition_copy(TSource begin, TSource end, TDestinationTrue destination_true, TDestinationFalse destination_false, TUnaryPredicate predicate)
Definition: algorithm.h:448
bool is_partitioned(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:399
std::pair< const T &, const T & > minmax(const T &a, const T &b, TCompare compare)
Definition: algorithm.h:104
TIterator find_if_not(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:229
TIterator is_sorted_until(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:141
bool none_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:272
TOutputIterator copy_if(TIterator begin, TIterator end, TOutputIterator out, TUnaryPredicate predicate)
Definition: algorithm.h:208
TOutputIterator copy_n(TInputIterator begin, Size count, TOutputIterator result)
Definition: algorithm.h:189
Definition: algorithm.h:43
bool any_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:261
TContainer::iterator end(TContainer &container)
Definition: container.h:95
TContainer::iterator begin(TContainer &container)
Definition: container.h:45
TIterator next(TIterator iterator, ptrdiff_t n=1)
Definition: container.h:245
std::pair< TIterator, TIterator > minmax_element(TIterator begin, TIterator end)
Definition: algorithm.h:80
bool is_sorted(TIterator begin, TIterator end, TCompare compare)
Definition: algorithm.h:178
bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TIterator2 end2, TBinaryPredicate predicate)
Definition: algorithm.h:372
bool all_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:250
TIterator partition_point(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition: algorithm.h:426