Date: Sat, 06 Jun 2026 00:46:13 +0000
For what it's worth, this could be done in C++26 if you would find it acceptable to spell it instead as
auto subrange = make_from_tuple<^^ranges::subrange>(m.equal_range(1));
If you accept a std::meta::info in the template parameter for make_from_tuple.
It's likely still beneficial to pursue universal templates as a language feature, but if you just wanted to write your own version of this function then you can in C++26.
On Friday, June 5th, 2026 at 10:39 AM, Hewill Kang via Std-Proposals <std-proposals_at_[hidden]> wrote:
> Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]> 於 2026年6月5日週五 下午11:23寫道:
>
>> 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.
>
> This is why I would be happy to see the standard introduce a universe template version of `make_from_tuple` if we once have a universe template, for example:
>
> template<template<universal template...> typename Templ, tuple-like Tuple>
> constexpr auto make_from_tuple(Tuple&& t);
>
> This allows us to spell things like the following:
>
> auto subrange = make_from_tuple<ranges::subrange>(m.equal_range(1));
>
> Using `template<template<typename...> typename Templ, tuple-like Tuple>` will not work because the template parameter of `subrange` is `template<class, class, subrange_kind>`, the last one is NTTP.
>
>> --
>> Rainer Deyke - rainerd_at_[hidden]
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
auto subrange = make_from_tuple<^^ranges::subrange>(m.equal_range(1));
If you accept a std::meta::info in the template parameter for make_from_tuple.
It's likely still beneficial to pursue universal templates as a language feature, but if you just wanted to write your own version of this function then you can in C++26.
On Friday, June 5th, 2026 at 10:39 AM, Hewill Kang via Std-Proposals <std-proposals_at_[hidden]> wrote:
> Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]> 於 2026年6月5日週五 下午11:23寫道:
>
>> 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.
>
> This is why I would be happy to see the standard introduce a universe template version of `make_from_tuple` if we once have a universe template, for example:
>
> template<template<universal template...> typename Templ, tuple-like Tuple>
> constexpr auto make_from_tuple(Tuple&& t);
>
> This allows us to spell things like the following:
>
> auto subrange = make_from_tuple<ranges::subrange>(m.equal_range(1));
>
> Using `template<template<typename...> typename Templ, tuple-like Tuple>` will not work because the template parameter of `subrange` is `template<class, class, subrange_kind>`, the last one is NTTP.
>
>> --
>> Rainer Deyke - rainerd_at_[hidden]
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-06-06 00:46:21
