std::sentinel_for(3)
std::sentinel_for π
okay bestie, this is the C++ Standard Libary page for std::sentinel_for, and it is literally giving βconcept that defines the relationship between an iterator and a sentinelβ energy. no cap, she matters for ranges. β¨
π NAME π
std::sentinel_for β the concept herself, fr fr.
πΈ Synopsis πΈ
Defined in header <iterator>.
template< class S, class I >
concept sentinel_for =
std::semiregular<S> && (since C++20)
std::input_or_output_iterator<I> &&
__WeaklyEqualityComparableWith<S, I>;
So hereβs the tea, bestie: the sentinel_for concept specifies the relationship between an input_or_output_iterator type and a semiregular type whose values denote a range. π«Ά
The exposition-only concept __WeaklyEqualityComparableWith is described in equality_comparable. iykyk.
π Semantic requirements π
Let s and i be values of type S and I, respectively, such that [i, s) denotes a range. sentinel_for<S, I> is modeled only if:
i == sis well-defined.- If
bool(i != s)theniis dereferenceable and[++i, s)denotes a range. std::assignable_from<I&, S>is either modeled or not satisfied.
The domain of == can change over time. 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 so i == s is no longer required to be well-defined after such an increment). π€― thatβs the plot twist, bestie.
π Notes π
- A sentinel type and its corresponding iterator type are not required to model
equality_comparable_with, because the sentinel type may not be comparable with itself, and they are not required to have a common reference type. periodt. - It has been permitted to use a sentinel type different from the iterator type in the range-based
forloop since C++17. (iykyk)
π¦ Defect reports π¦
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. not me keeping receipts π
- DR
LWG 3453- Applied to: C++20
- Behavior as published: semantic requirements for
sentinel_forwere too loose forranges::advance - Correct behavior: strengthened
source/version and date, bestie: http://cppreference.com, 2024.06.10. byeee, go model some ranges responsibly π§π
π¦ 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