std::ranges...:find_next,(3)
π NAME π
std::ranges::chunk_by_view::find_next β and also std::ranges::chunk_by_view::find_next bestie, the manpage really said it twice π β this is one of those internal helper things (/*find-next*/ and its little sister /*find-prev*/) from the C++ Standard Libary (yes that's the spelling up top, we keep it π).
β¨ SYNOPSIS β¨
constexpr ranges::iterator_t<V> (since C++23)
/*find-next*/( ranges::iterator_t<V> current ); (exposition only*)
That (since C++23) is doing a lot of heavy lifting ok β this is new-new π₯. And the (exposition only*)? That means she's an exposition-only icon, iykyk β she exists so the standard can explain herself, not so you can call her directly π«Ά.
πΈ DESCRIPTION πΈ
Ok so picture this: she finds the next chunk. That's it, that's the vibe.
Let base_ and pred_ be appropriate underlying data-members of chunk_by_view β¨.
Functionally she's equivalent to:
return ranges::next
(
ranges::adjacent_find
(
current, ranges::end(base_), std::not_fn(std::ref(*pred_))
),
1, ranges::end(base_)
);
Like, literally that. No cap. She does an ranges::adjacent_find with std::not_fn(std::ref(*pred_)) from current to ranges::end(base_), then ranges::next skips one past it, bounded by ranges::end(base_). Slay π
β οΈ The behavior is undefined ifpred_.has_value()is false before the call to this function. Like β genuinely undefined, not "undefined in a cute way". Check yourpred_first, bestie π
Used in the following non-static member functions:
ranges::chunk_by_view::iterator::operator++
So when you increment that iterator, this is the girl working behind the scenes π
π PARAMETERS π
currentβ the iterator to current element in adapted view π¦
π std::ranges::chunk_by_view::prev π
Ok different function, same energy. Here's her flexibility:
constexpr iterator_t<V>
(since C++23)
/*find-prev*/( ranges::iterator_t<V> current ) (exposition only*)
requires ranges::bidirectional_range<V>;
Note the requires ranges::bidirectional_range<V>; β she only shows up for bidirectional ranges, because obviously you can't go backwards through something that doesn't go backwards π
She finds the previous chunk β
Let base_ and pred_ be appropriate underlying data-members of chunk_by_view.
She returns an iterator i in the range [ranges::begin(base_), current) such that:
ranges::adjacent_find(i, current, std::not_fn(std::ref(*pred_)))is equal tocurrent, and- if
iis not equal toranges::begin(base_), thenbool(std::invoke(*pred_, *ranges::prev(i), *i))is false.
Both conditions. Not one, not the other β both. Periodt π
π The behavior is undefined if before the call to this functioncurrent == ranges::begin(base_)orpred_.has_value() != true. So don't call her at the very start, and don't call her with an emptypred_. That's the whole warning. Respect it π€
Used in the following non-static member functions:
ranges::chunk_by_view::iterator::operator--
Decrement squad represent π
π PARAMETERS π
currentβ the iterator to current element in adapted view.
β¨ that's the whole page bestie, go forth and chunk responsibly β¨
Sign-off vibes: this gem dropped from http://cppreference.com on 2024.06.10, filed under std::ranges...:find_next,(3) ππ¦π
π¦ 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