C++ Logo

std-discussion

Advanced search

Re: Are random-access proxy iterators really supported by the standard library?

From: Oleksandr Koval <oleksandr.koval.dev_at_[hidden]>
Date: Sat, 22 May 2021 23:53:47 +0300
It would be great if you are right. I checked the "algorithm requirements"
section and didn't find anything related to such constraints. I don't have
a Windows machine right now but from STL source code it looks like MS STL
uses `std::ranges::iter_swap()/iter_move()` as expected. My confusion comes
from the fact that cppreference says that GCC supports Ranges and I relied
on their implementation. And now I can't figure out whether it's my
misunderstanding or GCC hasn't implemented it yet.

On Sat, May 22, 2021 at 4:18 AM Jason McKesson via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> 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 mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>


-- 
Regards,
Oleksandr Koval.

Received on 2021-05-22 15:54:02