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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With