std::ranges...:find_next,(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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 if pred_.has_value() is false before the call to this function. Like β€” genuinely undefined, not "undefined in a cute way". Check your pred_ 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 to current, and
  • if i is not equal to ranges::begin(base_), then bool(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 function current == ranges::begin(base_) or pred_.has_value() != true. So don't call her at the very start, and don't call her with an empty pred_. 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