Files
cppdraft_translate/cppdraft/unreachable/sentinel.md
2025-10-25 03:02:53 +03:00

1.5 KiB
Raw Blame History

[unreachable.sentinel]

24 Iterators library [iterators]

24.5 Iterator adaptors [predef.iterators]

24.5.8 Unreachable sentinel [unreachable.sentinel]

1

#

Class unreachable_sentinel_t can be used with any weakly_incrementable type to denote the “upper bound” of an unbounded interval.

2

#

[Example 1: char* p;// set p to point to a character buffer containing newlineschar* nl = find(p, unreachable_sentinel, '\n');

Provided a newline character really exists in the buffer, the use ofunreachable_sentinel above potentially makes the call to find more efficient since the loop test against the sentinel does not require a conditional branch.

— end example]

🔗

namespace std {struct unreachable_sentinel_t {template<weakly_incrementable I>friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept{ return false; }};}