I can see that std::sort
returns void
. But now that ranges
have been added to the C++20 Standard, why does std::ranges::sort
return an iterator
? cppreference specifies:
Return value
An iterator equal to last.
void
? You don't have to pass an end iterator to the algorithms in std::ranges
. You can pass a sentinel instead, which is something comparable to an iterator, but it's not itself an iterator (it can't be dereferenced or incremented). Think of how this might be useful if you wanted to pass a null-terminated string to an algorithm.
std::ranges::sort
necessarily find the end of the sequence while doing it sorting. That's useful information, so it is returned.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.