23 Iterators library [iterators]

23.5 Iterator adaptors [predef.iterators]

23.5.7 Unreachable sentinel [unreachable.sentinels]

23.5.7.1 Class unreachable_­sentinel_­t [unreachable.sentinel]

Class unreachable_­sentinel_­t can be used with any WeaklyIncrementable type to denote the “upper bound” of an unbounded interval.
[Example
:
char* p;
// set p to point to a character buffer containing newlines
char* nl = find(p, unreachable_sentinel, '\n');
Provided a newline character really exists in the buffer, the use of unreachable_­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<WeaklyIncrementable I>
      friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept;
    template<WeaklyIncrementable I>
      friend constexpr bool operator==(const I&, unreachable_sentinel_t) noexcept;
    template<WeaklyIncrementable I>
      friend constexpr bool operator!=(unreachable_sentinel_t, const I&) noexcept;
    template<WeaklyIncrementable I>
      friend constexpr bool operator!=(const I&, unreachable_sentinel_t) noexcept;
  };
}

23.5.7.2 Comparisons [unreachable.sentinel.cmp]

template<WeaklyIncrementable I> friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept; template<WeaklyIncrementable I> friend constexpr bool operator==(const I&, unreachable_sentinel_t) noexcept;
Returns: false.
template<WeaklyIncrementable I> friend constexpr bool operator!=(unreachable_sentinel_t, const I&) noexcept; template<WeaklyIncrementable I> friend constexpr bool operator!=(const I&, unreachable_sentinel_t) noexcept;
Returns: true.