NON_MUTATING_ALGORITHMS(3)
π Non-Mutating Algorithms(3) π
okay bestie, this is the Library Functions Manual page for Non-Mutating Algorithms, part 1 of 3. It's giving very "read the docs but make it cute" energy, and we are keeping every single detail. No cap. π
π NAME π
Non-Mutating Algorithms - these are the non-mutating algorithm goodies, and the function lineup is literally:
π§ Functions π§
template<typename _ForwardIterator , typename _BinaryPredicate >
_ForwardIterator std::adjacent_find (_ForwardIterator __first,
_ForwardIterator __last, _BinaryPredicate __binary_pred)
template<typename _ForwardIterator > _ForwardIterator std::adjacent_find
(_ForwardIterator __first, _ForwardIterator __last)
template<typename _InputIterator , typename _Predicate > bool
std::all_of (_InputIterator __first, _InputIterator __last,
_Predicate __pred)
template<typename _InputIterator , typename _Predicate > bool
std::any_of (_InputIterator __first, _InputIterator __last,
_Predicate __pred)
template<typename _InputIterator , typename _Tp > iterator_traits<
_InputIterator >::difference_type std::count (_InputIterator
__first, _InputIterator __last, const _Tp &__value)
template<typename _InputIterator , typename _Predicate >
iterator_traits< _InputIterator >::difference_type std::count_if
(_InputIterator __first, _InputIterator __last, _Predicate __pred)
template<typename _IIter1 , typename _IIter2 , typename _BinaryPredicate
> bool std::equal (_IIter1 __first1, _IIter1 __last1, _IIter2
__first2, _BinaryPredicate __binary_pred)
template<typename _II1 , typename _II2 > bool std::equal (_II1 __first1,
_II1 __last1, _II2 __first2)
template<typename _InputIterator , typename _Tp > _InputIterator
std::find (_InputIterator __first, _InputIterator __last, const _Tp
&__val)
template<typename _ForwardIterator1 , typename _ForwardIterator2 ,
typename _BinaryPredicate > _ForwardIterator1 std::find_end
(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __comp)
template<typename _ForwardIterator1 , typename _ForwardIterator2 >
_ForwardIterator1 std::find_end (_ForwardIterator1 __first1,
_ForwardIterator1 __last1, _ForwardIterator2 __first2,
_ForwardIterator2 __last2)
template<typename _InputIterator , typename _ForwardIterator , typename
_BinaryPredicate > _InputIterator std::find_first_of (_InputIterator
__first1, _InputIterator __last1, _ForwardIterator __first2,
_ForwardIterator __last2, _BinaryPredicate __comp)
template<typename _InputIterator , typename _ForwardIterator >
_InputIterator std::find_first_of (_InputIterator __first1,
_InputIterator __last1, _ForwardIterator __first2, _ForwardIterator
__last2)
template<typename _InputIterator , typename _Predicate > _InputIterator
std::find_if (_InputIterator __first, _InputIterator __last,
_Predicate __pred)
template<typename _InputIterator , typename _Predicate > _InputIterator
std::find_if_not (_InputIterator __first, _InputIterator __last,
_Predicate __pred)
template<typename _InputIterator , typename _Function > _Function
std::for_each (_InputIterator __first, _InputIterator __last,
_Function __f)
template<typename _InputIterator1 , typename _InputIterator2 , typename
_BinaryPredicate > pair< _InputIterator1, _InputIterator2 >
std::mismatch (_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _BinaryPredicate __binary_pred)
template<typename _InputIterator1 , typename _InputIterator2 > pair<
_InputIterator1, _InputIterator2 > std::mismatch (_InputIterator1
__first1, _InputIterator1 __last1, _InputIterator2 __first2)
template<typename _InputIterator , typename _Predicate > bool
std::none_of (_InputIterator __first, _InputIterator __last,
_Predicate __pred)
template<typename _ForwardIterator1 , typename _ForwardIterator2 ,
typename _BinaryPredicate > _ForwardIterator1 std::search
(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __predicate)
template<typename _ForwardIterator1 , typename _ForwardIterator2 >
_ForwardIterator1 std::search (_ForwardIterator1 __first1,
_ForwardIterator1 __last1, _ForwardIterator2 __first2,
_ForwardIterator2 __last2)
template<typename _ForwardIterator , typename _Integer , typename _Tp ,
typename _BinaryPredicate > _ForwardIterator std::search_n
(_ForwardIterator __first, _ForwardIterator __last, _Integer
__count, const _Tp &__val, _BinaryPredicate __binary_pred)
template<typename _ForwardIterator , typename _Integer , typename _Tp >
_ForwardIterator std::search_n (_ForwardIterator __first,
_ForwardIterator __last, _Integer __count, const _Tp &__val)
π₯ Function Documentation π₯
π std::adjacent_find β the one with _BinaryPredicate π
template<typename _ForwardIterator , typename _BinaryPredicate >
_ForwardIterator std::adjacent_find (_ForwardIterator __first,
_ForwardIterator __last, _BinaryPredicate __binary_pred) [inline]
okay so this one hunts for two adjacent values in a sequence using a predicate. π
Parameters:
firstβ a forward iterator.lastβ a forward iterator.binary_predβ a binary predicate.
Returns: The first iterator i such that i and i+1 are both valid iterators in [first,last) and such that binary_pred(*i,*(i+1)) is true, or last if no such iterator exists.
Definition at line 4371 of file stl_algo.h.
π¦ std::adjacent_find β no predicate, just equality π¦
template<typename _ForwardIterator > _ForwardIterator std::adjacent_find
(_ForwardIterator __first, _ForwardIterator __last) [inline]
Same little search mission, but no custom predicate β it's looking for two adjacent values in a sequence that are equal. Literally neighbors matching. β¨
Parameters:
firstβ a forward iterator.lastβ a forward iterator.
Returns: The first iterator i such that i and i+1 are both valid iterators in [first,last) and such that *i == *(i+1), or last if no such iterator exists.
Definition at line 4339 of file stl_algo.h.
πΈ std::all_of πΈ
template<typename _InputIterator , typename _Predicate > bool std::all_of
(_InputIterator __first, _InputIterator __last, _Predicate __pred)
[inline]
Checks that a predicate is true for all the elements of a sequence. Like, every single one has to pass the vibe check. π
Parameters:
firstβ an input iterator.lastβ an input iterator.predβ a predicate.
Returns: True if the check is true, false otherwise.
Returns true if pred is true for each element in the range [first,last), and false otherwise.
Definition at line 744 of file stl_algo.h.
References std::find_if_not().
π std::any_of π
template<typename _InputIterator , typename _Predicate > bool std::any_of
(_InputIterator __first, _InputIterator __last, _Predicate __pred)
[inline]
Checks that a predicate is false for at least an element of a sequence β that's what the description line says, bestie. Then the Returns bit says true if an element exists where pred is true. Both facts stay. π«Ά
Parameters:
firstβ an input iterator.lastβ an input iterator.predβ a predicate.
Returns: True if the check is true, false otherwise.
Returns true if an element exists in the range [first,last) such that pred is true, and false otherwise.
Definition at line 778 of file stl_algo.h.
References std::none_of().
π§ std::count π§
template<typename _InputIterator , typename _Tp >
iterator_traits<_InputIterator>::difference_type std::count
(_InputIterator __first, _InputIterator __last, const _Tp & __value)
[inline]
Counts the number of copies of a value in a sequence. It's literally doing inventory. π¦
Parameters:
firstβ an input iterator.lastβ an input iterator.valueβ the value to be counted.
Returns: The number of iterators i in the range [first,last) for which *i == value
Definition at line 4403 of file stl_algo.h.
π std::count_if π
template<typename _InputIterator , typename _Predicate >
iterator_traits<_InputIterator>::difference_type std::count_if
(_InputIterator __first, _InputIterator __last, _Predicate __pred)
[inline]
Counts the elements of a sequence for which a predicate is true. Same counting energy, but the condition is your own custom little test. π₯
Parameters:
firstβ an input iterator.lastβ an input iterator.predβ a predicate.
Returns: The number of iterators i in the range [first,last) for which pred(*i) is true.
Definition at line 4428 of file stl_algo.h.
β std::equal β with _BinaryPredicate β
template<typename _IIter1 , typename _IIter2 , typename _BinaryPredicate >
bool std::equal (_IIter1 __first1, _IIter1 __last1, _IIter2 __first2,
_BinaryPredicate __binary_pred) [inline]
Tests a range for element-wise equality. Cute comparison behavior. π
Parameters:
first1β an input iterator.last1β an input iterator.first2β an input iterator.binary_predβ a binary predicate functor.
Returns: A boolean true or false.
This compares the elements of two ranges using the binary_pred parameter, and returns true or false depending on whether all of the corresponding elements of the ranges are equal.
Definition at line 984 of file stl_algobase.h.
π std::equal β using == π
template<typename _II1 , typename _II2 > bool std::equal (_II1 __first1,
_II1 __last1, _II2 __first2) [inline]
Tests a range for element-wise equality, no custom predicate needed. π
Parameters:
first1β an input iterator.last1β an input iterator.first2β an input iterator.
Returns: A boolean true or false.
This compares the elements of two ranges using == and returns true or false depending on whether all of the corresponding elements of the ranges are equal.
Definition at line 952 of file stl_algobase.h.
Referenced by std::operator==().
π¦ std::find π¦
template<typename _InputIterator , typename _Tp > _InputIterator std::find
(_InputIterator __first, _InputIterator __last, const _Tp & __val)
[inline]
Finds the first occurrence of a value in a sequence. First match wins, periodt. π
Parameters:
firstβ an input iterator.lastβ an input iterator.valβ the value to find.
Returns: The first iterator i in the range [first,last) such that *i == val, or last if no such iterator exists.
Definition at line 4215 of file stl_algo.h.
References std::__find(), and std::__iterator_category().
π«Ά std::find_end β with _BinaryPredicate π«Ά
template<typename _ForwardIterator1 , typename _ForwardIterator2 , typename
_BinaryPredicate > _ForwardIterator1 std::find_end (_ForwardIterator1
__first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_ForwardIterator2 __last2, _BinaryPredicate __comp) [inline]
Finds the last matching subsequence in a sequence using a predicate. Like, it's searching from the back of the group chat for the matching thread. π
Parameters:
first1β start of range to search.last1β end of range to search.first2β start of sequence to match.last2β end of sequence to match.compβ the predicate to use.
Returns: The last iterator i in the range [first1,last1-(last2-first2)) such that predicate(*(i+N), (first2+N)) is true for each N in the range [0,last2-first2), or last1 if no such iterator exists.
π¦ std::find_end β the one that takes comp
okay so this version hunts through [first1,last1) for a sub-sequence that compares equal value-by-value to the sequence given by [first2,last2) β except it uses comp as the predicate instead of plain ==. It hands you back an iterator to the first element of that sub-sequence, or last1 if the sub-sequence just isn't in there. And bestie, the sub-sequence it finds will be the last such subsequence contained in [first,last1). π
Because the sub-sequence has to lie completely within [first1,last1), it must start at a position less than last1-(last2-first2), where last2-first2 is the length of the sub-sequence. Which means the returned iterator i will be in the range [first1,last1-(last2-first2)). no cap. β¨
Definition at line 710 of file stl_algo.h.
References std::__iterator_category().
π std::find_end β find the last matching subsequence
template<typename _ForwardIterator1, typename _ForwardIterator2>
_ForwardIterator1 std::find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2) [inline]
Find last matching subsequence in a sequence. π
Parameters:
first1β start of range to search.last1β end of range to search.first2β start of sequence to match.last2β end of sequence to match.
Returns: the last iterator i in the range [first1,last1-(last2-first2)) such that *(i+N) == *(first2+N) for each N in the range [0,last2-first2), or last1 if no such iterator exists.
It searches the range [first1,last1) for a sub-sequence that compares equal value-by-value with the sequence given by [first2,last2) and returns an iterator to the first element of the sub-sequence, or last1 if the sub-sequence is not found. And again: the sub-sequence will be the last such subsequence contained in [first,last1). π«Ά
Because the sub-sequence must lie completely within the range [first1,last1) it must start at a position less than last1-(last2-first2) β last2-first2 being the length of the sub-sequence. This means the returned iterator i will be in the range [first1,last1-(last2-first2)). literally the same energy as above. π
Definition at line 663 of file stl_algo.h.
References std::__iterator_category().
π std::find_first_of β with a predicate
template<typename _InputIterator, typename _ForwardIterator, typename _BinaryPredicate>
_InputIterator std::find_first_of(_InputIterator __first1, _InputIterator __last1,
_ForwardIterator __first2, _ForwardIterator __last2,
_BinaryPredicate __comp) [inline]
Find element from a set in a sequence, but using a predicate. π₯
Parameters:
first1β start of range to search.last1β end of range to search.first2β start of match candidates.last2β end of match candidates.compβ predicate to use.
Returns: the first iterator i in the range [first1,last1) such that comp(*i, *(i2)) is true and i2 is an iterator in [first2,last2), or last1 if no such iterator exists.
So it searches [first1,last1) for an element that's equal to some element in [first2,last2). Found it? You get an iterator in the range [first1,last1). Not found? last1. that's it, that's the vibe. β¨
Definition at line 4308 of file stl_algo.h.
π std::find_first_of β the no-predicate version
template<typename _InputIterator, typename _ForwardIterator>
_InputIterator std::find_first_of(_InputIterator __first1, _InputIterator __last1,
_ForwardIterator __first2, _ForwardIterator __last2) [inline]
Find element from a set in a sequence. πΈ
Parameters:
first1β start of range to search.last1β end of range to search.first2β start of match candidates.last2β end of match candidates.
Returns: the first iterator i in the range [first1,last1) such that *i == *(i2) where i2 is an iterator in [first2,last2), or last1 if no such iterator exists.
Searches the range [first1,last1) for an element that is equal to some element in the range [first2,last2). If found, returns an iterator in the range [first1,last1); otherwise returns last1. simple as that bestie π
Definition at line 4268 of file stl_algo.h.
π§ std::find_if β predicate says yes
template<typename _InputIterator, typename _Predicate>
_InputIterator std::find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) [inline]
Find the first element in a sequence for which a predicate is true. π
Parameters:
firstβ an input iterator.lastβ an input iterator.predβ a predicate.
Returns: the first iterator i in the range [first,last) such that pred(*i) is true, or last if no such iterator exists.
Definition at line 4239 of file stl_algo.h.
References std::__find_if(), and std::__iterator_category().
π std::find_if_not β predicate says nope
template<typename _InputIterator, typename _Predicate>
_InputIterator std::find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) [inline]
Find the first element in a sequence for which a predicate is false. π yes, it's the inverse girlie.
Parameters:
firstβ an input iterator.lastβ an input iterator.predβ a predicate.
Returns: the first iterator i in the range [first,last) such that pred(*i) is false, or last if no such iterator exists.
Definition at line 793 of file stl_algo.h.
References std::__find_if_not(), and std::__iterator_category().
Referenced by std::all_of(), and std::is_partitioned().
π std::for_each β do the thing to every element
template<typename _InputIterator, typename _Function>
_Function std::for_each(_InputIterator __first, _InputIterator __last, _Function __f) [inline]
Apply a function to every element of a sequence. π«Ά
Parameters:
firstβ an input iterator.lastβ an input iterator.fβ a unary function object.
Returns: f.
It applies the function object f to each element in the range [first,last). Important: f must not modify the order of the sequence β do not be out here rearranging things, bestie π. And if f has a return value, it's ignored. periodt.
Definition at line 4194 of file stl_algo.h.
β std::mismatch β the predicate edition
template<typename _InputIterator1, typename _InputIterator2, typename _BinaryPredicate>
pair<_InputIterator1, _InputIterator2> std::mismatch(_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_BinaryPredicate __binary_pred) [inline]
Finds the places in ranges which don't match. π
Parameters:
first1β an input iterator.last1β an input iterator.first2β an input iterator.binary_predβ a binary predicate functor.
Returns: a pair of iterators pointing to the first mismatch.
This compares the elements of two ranges using the binary_pred parameter, and returns a pair of iterators. The first iterator points into the first range, the second iterator points into the second range, and the elements pointed to by the iterators are not equal. iconic honestly.
Definition at line 1128 of file stl_algobase.h.
π std::mismatch β the == edition
template<typename _InputIterator1, typename _InputIterator2>
pair<_InputIterator1, _InputIterator2> std::mismatch(_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2) [inline]
Finds the places in ranges which don't match. π¦
Parameters:
first1β an input iterator.last1β an input iterator.first2β an input iterator.
Returns: a pair of iterators pointing to the first mismatch.
This compares the elements of two ranges using == and returns a pair of iterators. The first iterator points into the first range, the second iterator points into the second range, and the elements pointed to by the iterators are not equal. same energy, no custom predicate needed β¨
Definition at line 1090 of file stl_algobase.h.
π₯ std::none_of β nobody gets a yes
template<typename _InputIterator, typename _Predicate>
bool std::none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) [inline]
Checks that a predicate is false for all the elements of a sequence. π
Parameters:
firstβ an input iterator.lastβ an input iterator.predβ a predicate.
Returns: true if the check is true, false otherwise.
So: returns true if pred is false for each element in the range [first,last), and false otherwise. yeah that's the whole thing π
Definition at line 761 of file stl_algo.h.
Referenced by std::any_of(), and std::is_partitioned().
πΈ std::search β sub-sequence hunting with a predicate
template<typename _ForwardIterator1, typename _ForwardIterator2, typename _BinaryPredicate>
_ForwardIterator1 std::search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __predicate) [inline]
Search a sequence for a matching sub-sequence, using a predicate. π§
Parameters:
first1β a forward iterator.last1β a forward iterator.first2β a forward iterator.last2β a forward iterator.predicateβ a binary predicate.
Returns: the first iterator i in the range [first1,last1-(last2-first2)) such that predicate(*(i+N),*(first2+N)) is true for each N in the range [0,last2-first2), or last1 if no such iterator exists.
It searches the range [first1,last1) for a sub-sequence that compares equal value-by-value with the sequence given by [first2,last2), using predicate to determine equality, and returns an iterator to the first element of the sub-sequence β or last1 if no such iterator exists. ate. π
See also: search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2)
Definition at line 4540 of file stl_algo.h.
π std::search β sub-sequence hunting, plain and simple
template<typename _ForwardIterator1, typename _ForwardIterator2>
_ForwardIterator1 std::search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2) [inline]
Search a sequence for a matching sub-sequence. β¨
Parameters:
first1β a forward iterator.last1β a forward iterator.first2β a forward iterator.last2β a forward iterator.
Returns: the first iterator i in the range [first1,last1-(last2-first2)) such that *(i+N) == *(first2+N) for each N in the range [0,last2-first2), or last1 if no such iterator exists.
Searches the range [first1,last1) for a sub-sequence that compares equal value-by-value with the sequence given by [first2,last2) and returns an iterator to the first element of the sub-sequence, or last1 if the sub-sequence is not found. π«Ά
Because the sub-sequence must lie completely within the range [first1,last1) it must start at a position less than last1-(last2-first2) where last2-first2 is the length of the sub-sequence. This means the returned iterator i will be in the range [first1,last1-(last2-first2)). iykyk π
Definition at line 4468 of file stl_algo.h.
π std::search_n β a whole run of the same value
template<typename _ForwardIterator, typename _Integer, typename _Tp, typename _BinaryPredicate>
_ForwardIterator std::search_n(_ForwardIterator __first, _ForwardIterator __last,
_Integer __count, const _Tp & __val,
_BinaryPredicate __binary_pred) [inline]
Search a sequence for a number of consecutive values, using a predicate. π
Parameters:
firstβ a forward iterator.lastβ a forward iterator.countβ the number of consecutive values.valβ the value to find.binary_predβ a binary predicate.
...and that's a wrap on that overload! π
Returns: the very first iterator i in the range [first,last-count) where binary_pred(*(i+N),val) is true for every N in the range [0,count) β or last if no such iterator exists. iykyk, no match = last, always. π
It searches the range [first,last) for count consecutive elements for which the predicate returns true. Bestie, it's literally hunting for a streak, not a single hit. π₯
Definition at line 4650 of file stl_algo.h.
References std::__iterator_category(), and std::__search_n().
β¨ the no-predicate version, aka the one you'll actually reach for β¨
template<typename _ForwardIterator , typename _Integer , typename _Tp >
_ForwardIterator std::search_n (_ForwardIterator __first,
_ForwardIterator __last, _Integer __count, const _Tp & __val) [inline]
Search a sequence for a number of consecutive values. Yes, exactly what it sounds like β the icon of "find me N of these in a row". π
Parameters:
firstβ a forward iterator. π«Άlastβ a forward iterator. (yes, another one, it takes two, that's how ranges work bestie)countβ the number of consecutive values. πvalβ the value to find.
Returns: the first iterator i in the range [first,last-count) such that *(i+N) == val for each N in the range [0,count), or last if no such iterator exists. Same energy as the predicate one, just without the custom comparison β plain old == doing its thing. π
It searches the range [first,last) for count consecutive elements equal to val.
Definition at line 4613 of file stl_algo.h.
References std::__iterator_category(), and std::__search_n().
πΈ Author πΈ
Generated automatically by Doxygen for libstdc++ from the source code. Not a human, not a vibe, just Doxygen doing Doxygen things. π€β¨
okay bye bestie!! π This whole page is libstdc++, dated 21 Apr 2009, straight out of the libstdc++ manual β go forth and search_n responsibly, mwah ππ¦π
π¦ where this page comes from
- nixpkgs unstable: std-man-pages 4.4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms