C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::range_of concept

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sun, 29 Sep 2024 16:32:20 -0400
On Sun, Sep 29, 2024 at 3:26 PM Avi Kivity via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I find it common to want to constrain a range to return a particular type.
> Something like
>
> void f(std::ranges::range_of<unsigned> auto&& range_of_unsigned) { ...
> }
>
> It would be trivial to define such a concept, or to forego the abbreviated
> template syntax and use a requires clause, but it seems to me this should
> be a vocabulary concept.
> There's the question of whether the type should be same_as or
> convertible_to, perhaps there is room for two concepts here.
>

This sounds like the same thing (in practice) as the exposition-only
*container-compatible-range*
<https://eel.is/c++draft/container.intro.reqmts#concept:container-compatible-range>
.
Which has not yet been made non-exposition-only, but I suspect it's only a
matter of time before someone brings a paper to that effect.

Note that technically you cannot write your own "STL-style" container — one
e.g. suitable as a backing store for std::stack
<https://eel.is/c++draft/stack#cons-4.sentence-1> — without knowing about
from_range_t and *container-compatible-range*. But the STL still gets away
with leaving it as exposition-only because it's literally a two-liner and
(because of how Concepts subsumption works) there's no difference between
using the actual STL's two-liner or writing the same two-liner in your own
namespace.

–Arthur

Received on 2024-09-29 20:32:34