C++ Logo


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

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

template<ranges::range R>
using borrowed_subrange_t = std::conditional_t<

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

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

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

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

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