std::experi...jacent_find(3)
okay bestie, welcome to the std::experi...jacent_find(3) page from the C++ Standard Libary manual β¨ this one is giving βalgorithm with a whole lot of template energy,β and weβre gonna walk through it together π
πΈ NAME πΈ
std::experimental::ranges::adjacent_find β and yeah, the name repeats: std::experimental::ranges::adjacent_find. It said it twice and meant it π
β¨ Synopsis β¨
Defined in header <experimental/ranges/algorithm>
template< ForwardIterator I, Sentinel<I> S, class Proj =
ranges::identity,
IndirectRelation<projected<I, Proj>> Pred =
(1) (ranges TS)
ranges::equal_to<> >
I adjacent_find( I first, S last, Pred pred = Pred{}, Proj proj =
Proj{} );
template< ForwardRange R, class Proj = ranges::identity,
IndirectRelation<projected<ranges::iterator_t<R>, Proj>>
Pred = ranges::equal_to<> >
(2) (ranges TS)
ranges::safe_iterator_t<R> adjacent_find( R&& r, Pred pred = Pred{},
Proj proj = Proj{} );
- Searches the range
[first, last)for two consecutive identical elements. Elements are compared usingpredafter being projected withproj. - Same as (1), but uses
ras the source range, as if usingranges::begin(r)asfirstandranges::end(r)aslast.
okay so important vibe check π¨ 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. no cap, thatβs a real warning bestie π
π Parameters π
first,lastβ the range of elements to examinerβ the range of elements to examinepredβ predicate to use to compare the projected elementsprojβ projection to apply to the elements
π Return value π
An iterator to the first of the first pair of identical elements, that is, the first iterator i such that both i and i + 1 are in the range [first, last) and
ranges::invoke(pred, ranges::invoke(proj, *i), ranges::invoke(proj,
*(i + 1))) !=
false.
If no such elements are found, an iterator that compares equal to last is returned.
π¦ Complexity π¦
If the range is nonempty, exactly min((result - first) + 1, (last - first) - 1) applications of the predicate where result is the return value, and at most twice as many applications of the projection.
π Possible implementation π
template<ForwardIterator I, Sentinel<I> S, class Proj =
ranges::identity,
IndirectRelation<projected<I, Proj>> Pred =
ranges::equal_to<>>
I adjacent_find(I first, S last, Pred pred = Pred{}, Proj proj =
Proj{})
{
if (first == last)
return first;
I next = first;
++next;
while (next != last)
{
if (ranges::invoke(pred, ranges::invoke(proj, *first),
ranges::invoke(proj, *next)))
return first;
++next;
++first;
}
return next;
}
π Example π
This section is incomplete.
Reason: no example
π See also π
adjacent_findβ finds the first two adjacent items that are equal (or satisfy a given predicate) (function template)uniqueβ removes consecutive duplicate elements in a range (function template)
π§ Category π§
Todo no example
made with π from http://cppreference.com, version/date 2024.06.10, on the std::experi...jacent_find(3) page. bye bestie, go find those adjacent twins π«Ά
π¦ 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