std::experi...es::find_end(3)
π NAME
okay so bestie, welcome to std::experi...es::find_end(3) β the manual page for the C++ Standard Library thing. The name is literally:
std::experimental::ranges::find_end β std::experimental::ranges::find_end
yes, both lines are the same, and no, that's not a typo, that's just how this page said it. We're keeping it. periodt.
β¨ Synopsis
First things first: it's defined in header <experimental/ranges/algorithm>.
Here are the declarations, copied exactly because bestie we do not mess with code:
Defined in header <experimental/ranges/algorithm>
template< ForwardIterator I1, Sentinel<I1> S1, ForwardIterator I2,
Sentinel<I2> S2,
class Proj = ranges::identity,
IndirectRelation<I2, projected<I1, Proj>> Pred =
(1) (ranges TS)
ranges::equal_to<> >
I1 find_end( I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = Pred{}, Proj proj = Proj{} );
template< ForwardRange R1, ForwardRange R2, class Proj =
ranges::identity,
IndirectRelation<ranges::iterator_t<R2>,
projected<ranges::iterator_t<R1>, Proj>>
(2) (ranges TS)
Pred = ranges::equal_to<> >
ranges::safe_iterator_t<R1> find_end( Rng1&& rng1, Rng2&& rng2,
Pred pred = Pred{}, Proj proj
= Proj{} );
- (1) searches for the last occurrence of the sequence
[first2, last2)in the range[first1, last1)(after projection withproj). - (2) same as (1), but uses
r1as the first source range andr2as the second source range, as if usingranges::begin(r1)asfirst1,ranges::end(r1)aslast1,ranges::begin(r2)asfirst2, andranges::end(r2)aslast2.
Okay, real talk: 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 the warning, bestie β don't play yourself. π
π«Ά Parameters
first1,last1β the range of elements to examine.r1β the range of elements to examine.first2,last2β the range of elements to search for.r2β the range of elements to search for.predβ predicate to compare the elements.projβ projection to apply to the elements in the first range.
π Return value
An iterator to the beginning of the last occurrence of the sequence [first2, last2) in range [first1, last1) (after projection with proj).
If [first2, last2) is empty or if no such sequence is found, you get an iterator that compares equal to last1. That's the vibe.
π¦ Complexity
At most S * (N - S + 1) applications of the predicate and projection, where S = last2 - first2 and N = last1 - first1.
πΈ Notes
The projection is only applied to the range [first1, last1). periodt.
π§ Possible implementation
Here's the possible implementation, exactly as the page gives it:
template<ForwardIterator I1, Sentinel<I1> S1, ForwardIterator I2,
Sentinel<I2> S2,
class Proj = ranges::identity,
IndirectRelation<I2, projected<I1, Proj>> Pred =
ranges::equal_to<>>
I1 find_end(I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = Pred{}, Proj proj = Proj{})
{
I1 result = ranges::next(first1, last1);
if (first2 == last2)
return result;
while (true)
{
I1 new_result = ranges::search(first1, last1, first2, last2,
pred, proj);
if (new_result == last1)
break;
else
{
result = new_result;
first1 = result;
++first1;
}
}
return result;
}
π Example
This section is incomplete Reason: no example
no example, bestie. We're not inventing one. π
π See also
find_endβ finds the last sequence of elements in a certain range (function template)searchβ searches for a range of elements (function template)includesβ returns true if one set is a subset of another (function template)adjacent_findβ finds the first two adjacent items that are equal (or satisfy a given predicate) (function template)findβ finds the first element satisfying specific criteria (function template)find_ifβ (function template)find_if_notβ (function template)find_first_ofβ searches for any one of a set of elements (function template)search_nβ searches for a number consecutive copies of an element in a range (function template)
π·οΈ Category
* Todo no example
π source/version/date check, bestie: http://cppreference.com, 2024.06.10, and the manual page is std::experi...es::find_end(3). mwah π
π¦ 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