C++ Logo

std-proposals

Advanced search

Re: [std-proposals] equal_range on unordered associative containers

From: Hewill Kang <hewillk_at_[hidden]>
Date: Fri, 5 Jun 2026 23:39:31 +0800
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-05 15:39:45