C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Are random-access proxy iterators really supported by the standard library?
From: Jason McKesson (jmckesson_at_[hidden])
Date: 2021-05-21 20:17:47


On Fri, May 21, 2021 at 6:03 PM Oleksandr Koval via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hi, in his tweet, Eric Niebler says that one can have a random-access proxy iterator in C++20. I've read his series of articles and also this paper but there's one thing I can't understand. Let's take `std::ranges::sort()` for example, it requires input range to be `std::sortable` which in turn requires `std::indirectly_swappable` which is specified in terms of `std::ranges::iter_swap()` which is a customization point for such proxy iterators. The question is: is `std::ranges::sort()` itself required to use `std::ranges::iter_swap()` internally? I can't find such a requirement and libstdc++ doesn't use it(unlike range-v3). Without it, there's no sense in satisfying `std::sortable` and the whole point of the random-access proxy iterator is gone. It can't work if algorithms don't use these customization points. It's pretty strange that algorithms are constrained by concepts which they don't have to use in the actual implementation.

I don't have an exact standard citation, but my general understanding
is that the requirements for such functions are both prescriptive and
proscriptive. That is, they represent a contract between the user and
the implementation: you must provide the functionality as specified by
the concepts and other requirements, and the implementations may not
use functionality that you are not required to provide.

So unless `std::ranges::sort` has a specific requirement allowing it
to call something like `ranges::swap` or whatever, the implementation
may not do so.


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups