Open
Description
An incorrect description of an example was spotted on Stack Overflow (the comment under the question), [unreachable.sentinel] p2 says:
[Example 1 :
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 tofind
more efficient since the loop test against the sentinel does not require a conditional branch. — end
example]
The description says that the example is well-defined if a null character is reachable from p
, but std::ranges::find
requires the input range to be valid, as [iterator.requirements.general] p12 says:
The result of the application of library functions to invalid ranges is undefined.