C++ Logo

std-proposals

Advanced search

rename C++20 borrowed_subrange_t to borrowed_common_subrange_t

From: kang hewill <hewillk_at_[hidden]>
Date: Thu, 25 Mar 2021 21:35:24 +0800
Hi,

The Ranges Illuminati introduced the ranges::borrowed_rangeconcept in
C++20, which defines requirements of a range such that a function can take
it by value and return iterators obtained from it without danger of dangling
.

At the same time, the type helper borrowed_subrange_t have also been
introduced:

template<ranges::range R>
using borrowed_subrange_t = std::conditional_t<
    ranges::borrowed_range<R>,
    ranges::subrange<ranges::iterator_t<R>>,
    ranges::dangling
>;

whenR models borrowed_range, this type is just
subrange<ranges::iterator_t<R>>, and more *importantly*, it is *also* an
ranges::common_range!

So I think it is more appropriate to name it
borrowed_common_subrange_t, consider
following:

auto r = std::views::iota(0);
auto s = ranges::subrange{r.begin(), r.end()};
static_assert(ranges::borrowed_range<decltype(s)>);

To some extent, the subranges also can be regarded as borrowed subrange type
of r, this kind of naming can be confusing:

auto b = ranges::borrowed_subrange_t<decltype(r)>{r}; // error and... why?

It will be more intuitive and more informative if we just add a common for
it:

auto b = ranges::borrowed_common_subrange_t<decltype(r)>{r}; // yes, r
is not common_range

What do you think?

Received on 2021-03-25 08:35:19