Date: Fri, 5 Jun 2026 17:23:14 +0200
On 6/5/26 14:40, Hewill Kang wrote:
> Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]> 於
> 2026年6月5日週五 下午6:09寫道:
>> Add a free function to convert a std::pair of iterators into a
>> std::ranges::subrange. This is the safest solution; highly unlikely to
>> break user code and any user code it does breaks is the fault of the user.
>>
>>
> Yep, but it can be done very easily with:
>
> auto to_subrange = [](auto&&... iters) { return
> std::ranges::subrange(iters...); };
> auto subrange = std::apply(to_subrange, m.equal_range(1));
Yes, it's a fairly simple function to write. The same can be said for
much of the standard library.
Once I have a named function, I need to worry about what to name it,
where to put it, and how to package it and distribute to where it needs
to go. I either need to put this function in an existing library,
create a new library just for the function, or write the function over
and over again for every project that needs it. Possible, but annoying.
Or I could just not name the function.
auto subrange = [](auto &&p){ return std::ranges::subrange(p.first,
p.second); }(m.equal_range(1));
Not quite as idiomatic as I would like, but it works.
> Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]> 於
> 2026年6月5日週五 下午6:09寫道:
>> Add a free function to convert a std::pair of iterators into a
>> std::ranges::subrange. This is the safest solution; highly unlikely to
>> break user code and any user code it does breaks is the fault of the user.
>>
>>
> Yep, but it can be done very easily with:
>
> auto to_subrange = [](auto&&... iters) { return
> std::ranges::subrange(iters...); };
> auto subrange = std::apply(to_subrange, m.equal_range(1));
Yes, it's a fairly simple function to write. The same can be said for
much of the standard library.
Once I have a named function, I need to worry about what to name it,
where to put it, and how to package it and distribute to where it needs
to go. I either need to put this function in an existing library,
create a new library just for the function, or write the function over
and over again for every project that needs it. Possible, but annoying.
Or I could just not name the function.
auto subrange = [](auto &&p){ return std::ranges::subrange(p.first,
p.second); }(m.equal_range(1));
Not quite as idiomatic as I would like, but it works.
-- Rainer Deyke - rainerd_at_[hidden]
Received on 2026-06-05 15:23:23
