75template <
class Itor,
class Operation>
76inline Operation
for_each(Itor beg,
const Itor & end, Operation op)
98template<
class Itor,
class Operation>
99[[nodiscard]]
inline typename Itor::difference_type
102 typename Itor::difference_type n = 0;
125template <
class Itor,
class T>
126[[nodiscard]]
inline typename Itor::difference_type
149 CompFunc op = CompFunc())
184[[nodiscard]]
inline Itor
max_element(
const Itor& beg,
const Itor& end,
185 CompFunc op = CompFunc())
204template<
class Itor,
class UnaryPredicate>
205[[nodiscard]]
inline Itor
find_if(Itor beg,
const Itor & end, UnaryPredicate op)
207 while (beg != end
and not op(*beg))
210 assert(beg == end or op(*beg));
229template<
class Itor,
class T>
230[[nodiscard]]
inline Itor
find(
const Itor & beg,
const Itor & end,
const T &
value)
253template<
class Itor,
class Size,
class T,
261 if (
count <= 0 or beg == end)
307template<
class Itor1,
class Itor2,
309[[nodiscard]]
inline Itor1
search(Itor1 beg,
const Itor1 & end,
310 Itor2 searchBeg,
const Itor2 & searchEnd,
313 if (beg == end or searchBeg == searchEnd)
317 Itor2 pivot = searchBeg;
320 while (beg != end
and pivot != searchEnd)
322 if (op(*beg, *pivot))
339 if (pivot == searchEnd)
362template<
class Itor1,
class Itor2,
364[[nodiscard]]
inline Itor1
find_end(Itor1 beg, Itor1 end,
365 Itor2 searchBeg, Itor2 searchEnd,
368 if (beg == end or searchBeg == searchEnd)
374 Itor1 new_ret =
search(beg, end, searchBeg, searchEnd, op);
403template<
class Itor1,
class Itor2,
406 Itor2 searchBeg,
const Itor2& searchEnd,
409 while (searchBeg != searchEnd)
413 while (current != end)
415 if (op(*current, *searchBeg))
480template <
class Itor1,
class Itor2,
482[[nodiscard]]
inline bool equal(Itor1 beg,
const Itor1 & end,
487 if (not op(*beg, *cmpBeg))
513template <
class Itor1,
class Itor2,
515[[nodiscard]]
inline std::pair<Itor1, Itor2>
520 while (beg != end
and op(*beg, *cmpBeg))
526 return std::make_pair(beg, cmpBeg);
545template <
class Itor1,
class Itor2,
548 Itor2 beg2,
const Itor2 & end2,
551 while (beg1 != end1
and beg2 != end2)
553 if (op(*beg1, *beg2))
555 else if (op(*beg2, *beg1))
562 return beg1 == end1
and beg2 != end2;
583template <
class Itor1,
class Itor2>
584inline Itor2
copy(Itor1 sourceBeg,
const Itor1& sourceEnd, Itor2 destBeg)
586 while (sourceBeg != sourceEnd)
587 *destBeg++ = *sourceBeg++;
606template <
class Itor1,
class Itor2>
607inline Itor2
copy_backward(
const Itor1 & sourceBeg, Itor1 sourceEnd, Itor2 destEnd)
609 while (sourceBeg != sourceEnd)
610 *--destEnd = *--sourceEnd;
631template <
class Itor1,
class Itor2,
class UnaryFunc>
633 Itor2 destBeg, UnaryFunc op)
635 while (sourceBeg != sourceEnd)
636 *destBeg++ = op(*sourceBeg++);
659template <
class Itor1,
class Itor2,
class Itor3,
class BinaryFunc>
660inline Itor3
transform(Itor1 source1Beg, Itor1 source1End,
665 while (source1Beg != source1End)
666 *destBeg++ = op(*source1Beg++, *source2Beg++);
685template <
class Itor1,
class Itor2>
686inline Itor2
swap_ranges(Itor1 beg1,
const Itor1& end1, Itor2 beg2)
689 std::swap(*beg1++, *beg2++);
706template <
class Itor,
class T>
726template <
class Itor,
class T,
class Size>
745template <
class Itor,
class Func>
746inline void generate(Itor beg,
const Itor& end, Func op)
765template <
class Itor,
class Size,
class Func>
787template <
class Itor,
class UnaryPredicate,
class T>
814template <
class Itor,
class T>
841template <
class Itor1,
class Itor2,
class UnaryPredicate,
class T>
847 while (sourceBeg != sourceEnd)
852 *destBeg++ = *sourceBeg;
877template <
class Itor1,
class Itor2,
class T>
878inline Itor2
replace_copy(
const Itor1& sourceBeg,
const Itor1& sourceEnd,
904template <
class In_Itor,
class Out_Itor,
class Predicate>
909 for ( ; __first != __last; ++__first)
910 if (not __pred(*__first))
912 *__result = *__first;
933template<
class Fw_Itor,
class Predicate>
934inline Fw_Itor
remove_if(Fw_Itor __first,
const Fw_Itor & __last,
939 Fw_Itor __i = __first;
941 if (__first == __last)
961template<
class Fw_Itor,
class T>
962inline Fw_Itor
remove(Fw_Itor __first,
const Fw_Itor & __last,
970template<
class In_Itor,
class Out_Itor,
972static inline Out_Itor __unique_copy(In_Itor __first, In_Itor __last,
974 BinaryPredicate __binary_pred = BinaryPredicate())
976 typename In_Itor::value_type __value = *__first;
980 while (++__first != __last)
981 if (not __binary_pred(__value, *__first))
984 *++__result = __value;
1005template<
class In_Itor,
class Out_Itor>
1009 if (__first == __last)
1012 return Aleph::__unique_copy(__first, __last, __result);
1031template <
class In_Itor,
class Out_Itor,
class BinaryPredicate>
1036 if (__first == __last)
1039 return Aleph::__unique_copy(__first, __last, __result, __binary_pred);
1064 if (__first == __last)
1068 Itor __dest = __first;
1071 while (++__first != __last)
1072 if (not __binary_pred(*__dest, *__first))
1073 *++__dest = *__first;
1093template <
class Itor>
1096 while (beg != end
and beg != --end)
1097 std::swap(*beg++, *end);
1113template <
class Itor1,
class Itor2>
1116 while (sourceBeg != sourceEnd)
1119 *destBeg = *sourceEnd;
1137template <
class Itor>
1138inline void rotate(Itor beg, Itor pos, Itor end)
1160template <
class Itor1,
class Itor2>
1161inline Itor2
rotate_copy(
const Itor1& beg,
const Itor1& pos,
const Itor1& end,
1189template <
class Itor,
class T>
1192 while (beg != end
and *beg <
value)
1214template <
class Itor,
class T,
class BinaryPredicate>
1218 while (beg != end
and op(*beg,
value))
1238template <
class Itor,
class T>
1241 while (beg != end
and not (
value < *beg))
1260template <
class Itor,
class T,
class BinaryPredicate>
1264 while (beg != end
and (op(*beg,
value) or not op(
value, *beg)))
1283template<
class Itor,
class T>
1287 return i != end
and not (
value < *i);
1306template<
class Itor,
class T,
class BinaryPredicate>
1311 return i != end
and not op(
value, *i);
1328template <
class Itor,
class T>
1329[[nodiscard]]
inline std::pair<Itor, Itor>
1349template <
class Itor,
class T,
class BinaryPredicate>
1350[[nodiscard]]
inline std::pair<Itor, Itor>
1372template <
class Itor1,
class Itor2>
1373[[nodiscard]]
inline bool includes(Itor1 beg, Itor1 end,
1374 Itor2 searchBeg, Itor2 searchEnd)
1376 while (beg != end
and searchBeg != searchEnd)
1378 if (*searchBeg < *beg)
1380 else if (*beg < *searchBeg)
1389 return searchBeg == searchEnd;
1409template <
class Itor1,
class Itor2,
class Itor3>
1410inline Itor3
merge(Itor1 source1Beg, Itor1 source1End,
1411 Itor2 source2Beg, Itor2 source2End,
1414 while (source1Beg != source1End
and source2Beg != source2End)
1416 if (*source2Beg < *source1Beg)
1418 *destBeg = *source2Beg;
1423 *destBeg = *source1Beg;
1451template <
class Itor1,
class Itor2,
class Itor3,
class BinaryPredicate>
1452inline Itor3
merge(Itor1 source1Beg, Itor1 source1End,
1453 Itor2 source2Beg, Itor2 source2End,
1456 while (source1Beg != source1End
and source2Beg != source2End)
1458 if (op(*source2Beg, *source1Beg))
1460 *destBeg = *source2Beg;
1465 *destBeg = *source1Beg;
1492template <
class Itor,
class T>
1495 for ( ; beg != end; ++beg)
1496 initValue = initValue + *beg;
1517template <
class Itor,
class T,
class BinaryFunc>
1518[[nodiscard]]
inline T accumulate(Itor beg, Itor end,
T initValue, BinaryFunc op)
1520 for ( ; beg != end; ++beg)
1521 initValue = op(initValue, *beg);
1542template <
class Itor1,
class Itor2,
class T>
1545 for ( ; beg1 != end1; ++beg1, ++beg2)
1546 initValue = initValue + (*beg1 * *beg2);
1571template <
class Itor1,
class Itor2,
class T,
class BinaryFunc1,
class BinaryFunc2>
1573 T initValue, BinaryFunc1 op1, BinaryFunc2 op2)
1575 for ( ; beg1 != end1; ++beg1, ++beg2)
1576 initValue = op1(initValue, op2(*beg1, *beg2));
1595template <
class Itor1,
class Itor2>
1596inline Itor2
partial_sum(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
1598 if (sourceBeg == sourceEnd)
1601 typename Itor1::value_type
sum = *sourceBeg;
1606 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1630template <
class Itor1,
class Itor2,
class BinaryFunc>
1632 Itor2 destBeg, BinaryFunc op)
1634 if (sourceBeg == sourceEnd)
1637 typename Itor1::value_type
sum = *sourceBeg;
1642 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1644 sum = op(
sum, *sourceBeg);
1666template <
class Itor1,
class Itor2>
1669 if (sourceBeg == sourceEnd)
1672 typename Itor1::value_type prev = *sourceBeg;
1677 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1679 typename Itor1::value_type curr = *sourceBeg;
1680 *destBeg = curr - prev;
1702template <
class Itor1,
class Itor2,
class BinaryFunc>
1704 Itor2 destBeg, BinaryFunc op)
1706 if (sourceBeg == sourceEnd)
1709 typename Itor1::value_type prev = *sourceBeg;
1714 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1716 typename Itor1::value_type curr = *sourceBeg;
1717 *destBeg = op(curr, prev);
Debug assertion and warning utilities.
General utility functions and helpers.
size_t size_t int32_t value
A callable that takes two const T& and returns bool.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
Itor lower_bound(Itor beg, Itor end, const T &value)
Find lower bound in a sorted range.
std::pair< Itor1, Itor2 > mismatch(Itor1 beg, const Itor1 &end, Itor2 cmpBeg, BinaryPredicate op=BinaryPredicate())
Find the first mismatching elements in two ranges.
void reverse(Itor beg, Itor end)
Reverse elements in a range.
Itor unique(Itor __first, Itor __last, BinaryPredicate __binary_pred=BinaryPredicate())
Remove consecutive duplicates in place.
Itor2 partial_sum(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
Compute partial sums of a range.
Itor2 copy_backward(const Itor1 &sourceBeg, Itor1 sourceEnd, Itor2 destEnd)
Copy elements backward from one range to another.
Itor1 find_end(Itor1 beg, Itor1 end, Itor2 searchBeg, Itor2 searchEnd, BinaryPredicate op=BinaryPredicate())
Find the last occurrence of a subrange.
void generate(Itor beg, const Itor &end, Func op)
Generate values for a range.
T inner_product(Itor1 beg1, Itor1 end1, Itor2 beg2, T initValue)
Compute inner product of two ranges.
binder2nd< _Operation > bind2nd(const _Operation &__fn, const _Tp &__x)
void replace_if(Itor beg, const Itor &end, UnaryPredicate op, const T &value)
Replace elements satisfying a predicate.
Out_Itor unique_copy(In_Itor __first, In_Itor __last, Out_Itor __result)
Copy unique elements.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
bool lexicographical_compare(Itor1 beg1, const Itor1 &end1, Itor2 beg2, const Itor2 &end2, Comp op=Comp())
Lexicographical comparison of two ranges.
void fill(Itor beg, const Itor &end, const T &value)
Fill a range with a value.
Out_Itor remove_copy_if(In_Itor __first, const In_Itor &__last, Out_Itor __result, Predicate __pred)
Copy elements not satisfying a predicate.
std::decay_t< typename HeadC::Item_Type > T
Itor2 adjacent_difference(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
Compute adjacent differences.
Itor adjacent_find(Itor beg, const Itor &end, BinaryPredicate op=BinaryPredicate())
Find first pair of adjacent equal elements.
T accumulate(Itor beg, Itor end, T initValue)
Accumulate values in a range.
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
Itor2 swap_ranges(Itor1 beg1, const Itor1 &end1, Itor2 beg2)
Swap elements between two ranges.
Itor min_element(Itor beg, const Itor &end, CompFunc op=CompFunc())
Find the minimum element in a range.
Itor2 replace_copy_if(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg, UnaryPredicate op, const T &value)
Copy and replace elements satisfying a predicate.
and
Check uniqueness with explicit hash + equality functors.
Itor upper_bound(Itor beg, Itor end, const T &value)
Find upper bound in a sorted range.
Fw_Itor remove(Fw_Itor __first, const Fw_Itor &__last, const T &__value)
Remove elements equal to a value.
Itor search_n(Itor beg, const Itor &end, Size count, const T &value, BinaryPredicate op=BinaryPredicate())
Find n consecutive elements equal to a value.
Itor1 search(Itor1 beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Search for a subrange within a range.
bool equal(Itor1 beg, const Itor1 &end, Itor2 cmpBeg, BinaryPredicate op=BinaryPredicate())
Test if two ranges are equal.
Itor2 transform(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg, UnaryFunc op)
Transform elements using a unary operation.
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
void fill_n(Itor beg, Size num, const T &value)
Fill n elements with a value.
Itor1 find_first_of(const Itor1 &beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Find first element from a set.
Itor2 replace_copy(const Itor1 &sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg, const T &old_value, const T &new_value)
Copy and replace elements equal to a value.
Fw_Itor remove_if(Fw_Itor __first, const Fw_Itor &__last, Predicate __pred)
Remove elements satisfying a predicate.
Itor3 merge(Itor1 source1Beg, Itor1 source1End, Itor2 source2Beg, Itor2 source2End, Itor3 destBeg)
Merge two sorted ranges.
bool binary_search(Itor beg, Itor end, const T &value)
Binary search for a value.
Itor::difference_type count_if(Itor beg, const Itor &end, Operation op)
Count elements satisfying a predicate.
void generate_n(Itor beg, Size num, Func op)
Generate values for n elements.
bool includes(Itor1 beg, Itor1 end, Itor2 searchBeg, Itor2 searchEnd)
Test if one sorted range includes another.
std::pair< Itor, Itor > equal_range(Itor beg, Itor end, const T &value)
Find equal range in a sorted sequence.
Itor2 reverse_copy(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
Copy elements in reverse order.
void next()
Advance all underlying iterators (bounds-checked).
Itor max_element(const Itor &beg, const Itor &end, CompFunc op=CompFunc())
Find the maximum element in a range.
void replace(Itor beg, const Itor &end, const T &old_value, const T &new_value)
Replace elements equal to a value.
Itor find_if(Itor beg, const Itor &end, UnaryPredicate op)
Find the first element satisfying a predicate.
void rotate(Itor beg, Itor pos, Itor end)
Rotate elements in a range.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Itor2 rotate_copy(const Itor1 &beg, const Itor1 &pos, const Itor1 &end, Itor2 tgt_beg)
Copy and rotate elements.