std::experi...es::Sentinel(3)

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

πŸ’– NAME πŸ’–

std::experimental::ranges::Sentinel β€” bestie, it's the concept that says "yes, this sentinel type and this iterator type are literally a whole range together" ✨


🌸 Synopsis 🌸

okay so first things first, it lives in this header:

<experimental/ranges/iterator>

and here's the whole vibe, copied exactly because I would never mess with your declarations:

template< class S, class I >

concept bool Sentinel =                           (ranges TS)
    Semiregular<S> && Iterator<I> &&

    WeaklyEqualityComparableWith<S, I>;

No cap, that's the entire concept. S is your sentinel, I is your iterator, and they have to be cute together. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

So the Sentinel concept specifies the relationship between an Iterator type and a Semiregular type whose values denote a range. That's it. That's the whole job. A semiregular little buddy hanging out at the end of your iterator range, marking where the party stops. πŸ’…

Let s and i be values of type S and I, respectively, such that [i, s) denotes a range. Then Sentinel<S, I> is satisfied only if these two things hold:

  • i == s is well-defined. (fr fr, the comparison has to actually make sense, no undefined behaviour shenanigans πŸ™ˆ)
  • If bool(i != s), then i is dereferenceable and [++i, s) denotes a range. (like, if you're not at the sentinel yet, you'd better be pointing at something real, and stepping forward had better keep you inside the range.)

⚠️ the domain-of-== situation ⚠️

bestie, listen to me, this part matters πŸ‘‘

The domain of == can change over time. That is not a bug, that's just how it is.

Given an iterator i and sentinel s such that [i, s) denotes a range and i != s, [i, s) is not required to continue to denote a range after incrementing any iterator equal to i.

And because of that: i == s is no longer required to be well-defined after such an increment. 😭

So yeah β€” you can't just go incrementing and then assume the comparison still means anything. The concept said what it said. Don't come for it. πŸ’€


πŸŽ€ see you, bestie πŸŽ€

that's the whole page, mwah πŸ’‹ β€” this slay little number came from http://cppreference.com, dated 2024.06.10, and it was brought to you by the manpage formerly known as std::experi...es::Sentinel(3). go forth and iterate responsibly, ily! πŸŒˆπŸ’–

πŸ“¦ where this page comes from