std::experi...es::find_if,(3)
π
std::experimental::ranges::find / find_if / find_if_not β C++ Standard Libary (section 3) π
Manual name: C++ Standard Libary (yes, the source spells it like that, bestie π). Section: (3). This is the ranges-TS era of the algorithm page, so buckle up.
πΈ NAME πΈ
Bestie, the source NAME line is literally:
std::experimental::ranges::find,std::experimental::ranges::find_if, - std::experimental::ranges::find,std::experimental::ranges::find_if,
And the synopsis also brings std::experimental::ranges::find_if_not into the group chat. We are not editing that comma chaos. π
π¦ Synopsis π¦
Defined in header <experimental/ranges/algorithm>.
Okay so here are all six overloads, with their (ranges TS) badges. Code is copied exactly; do not let the line wraps gaslight you.
(1) (ranges TS)
template< InputIterator I, Sentinel<I> S, class T, class Proj =
ranges::identity >
requires IndirectRelation<ranges::equal_to<>, projected<I,
Proj>, const T*>
I find( I first, S last, const T& value, Proj proj = Proj{} );
(2) (ranges TS)
template< InputRange R, class T, class Proj = ranges::identity >
requires IndirectRelation<ranges::equal_to<>,
projected<ranges::iterator_t<R>,
Proj>, const T*>
ranges::safe_iterator_t<R> find( R&& r, const T& value, Proj proj =
Proj{} );
(3) (ranges TS)
template< InputIterator I, Sentinel<I> S, class Proj =
ranges::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred >
I find_if( I first, S last, Pred pred, Proj proj = Proj{} );
(4) (ranges TS)
template< InputRange R, class Proj = ranges::identity,
IndirectUnaryPredicate<projected<ranges::iterator_t<R>,
Proj>> Pred >
ranges::safe_iterator_t<R> find_if( R&& r, Pred pred, Proj proj =
Proj{} );
(5) (ranges TS)
template< InputIterator I, Sentinel<I> S, class Proj =
ranges::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred >
I find_if_not( I first, S last, Pred pred, Proj proj = Proj{} );
(6) (ranges TS)
template< InputRange R, class Proj = ranges::identity,
IndirectUnaryPredicate<projected<ranges::iterator_t<R>,
Proj>> Pred >
ranges::safe_iterator_t<R> find_if_not( R&& r, Pred pred, Proj proj
= Proj{} );
Returns the first element in the range [first, last) that satisfies specific criteria:
- 1)
findsearches for an element whose projected value is equal tovalue(i.e.,value == ranges::invoke(proj, *i)). - 3)
find_ifsearches for an element for whose projected value predicatepreturnstrue(i.e.,ranges::invoke(pred, ranges::invoke(proj, *i)))istrue). - 5)
find_if_notsearches for an element for whose projected value predicateqreturnsfalse(i.e.,ranges::invoke(pred, ranges::invoke(proj, *i)))isfalse). - 2,4,6) Same as
(1,3,5), but usesras the source range, as if usingranges::begin(r)asfirstandranges::end(r)aslast.
Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable. That's a real caveat, bestie β not just vibes.
π Parameters π
first, lastβ the range of elements to examinerβ the range of elements to examinevalueβ value to compare the projected elements topredβ predicate to apply to the projected elementsprojβ projection to apply to the elements
π«Ά Return value π«Ά
Iterator to the first element satisfying the condition. If no such element is found, returns an iterator that compares equal to last.
β‘ Complexity β‘
At most last - first applications of the predicate and projection.
π οΈ Possible implementation π οΈ
π First version π
template<InputIterator I, Sentinel<I> S, class T, class Proj =
ranges::identity>
requires IndirectRelation<ranges::equal_to<>, projected<I, Proj>, const T*>
I find(I first, S last, const T& value, Proj proj = Proj{})
{
for (; first != last; ++first)
if (ranges::invoke(proj, *first) == value)
break;
return first;
}
π Second version π
template<InputIterator I, Sentinel<I> S, class Proj =
ranges::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred>
I find_if(I first, S last, Pred pred, Proj proj = Proj{})
{
for (; first != last; ++first)
if (ranges::invoke(pred, ranges::invoke(proj, *first)))
break;
return first;
}
π Third version π
template<InputIterator I, Sentinel<I> S, class Proj =
ranges::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred>
I find_if_not(I first, S last, Pred pred, Proj proj = Proj{})
{
for (; first != last; ++first)
if (!ranges::invoke(pred, ranges::invoke(proj, *first)))
break;
return first;
}
π Example π
This section is incomplete. Reason: no example. Not me leaving you on read β that's literally what the page says π.
π See also π
The source's table got line-wrapped into a whole situation. Every reference token is here:
findfind_ifβ finds the first element satisfying specific criteria β(function template)find_if_notβ(function template); the source also has a(C++11)token right after this in the wrap chaosadjacent_findβ finds the first two adjacent items that are equal (or satisfy a given predicate) β(function template)find_endβ finds the last sequence of elements in a certain range β(function template)find_first_ofβ searches for any one of a set of elements β(function template)mismatchβ finds the first position where two ranges differ β(function template)searchβ searches for a range of elements β(function template)
π Category
Todo no example
π source/version: http://cppreference.com Β· date: 2024.06.10 β bye bestie, go find your element! π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms