Why is there no range-pair-adapter for iterating over multimap::equal_range?

2 weeks ago 11
ARTICLE AD BOX

Why can I still not do something like:

std::multimap<int, std::string> data; data.insert({1, "A"}); data.insert({1, "B"}); data.insert({2, "C"}); for (auto val : data.equal_range(1)) { // this cannot compile std::cout << pair.first << ": " << pair.second << std::endl; }

I understand that std::ranges::subrange() doesn't support pair<It,It> (it was removed), but why not either:

a) specify multimap<>::equal_range_r() that returns an std::range rather than std::pair

or

b) define a small adapter like:

template <class T, class U> auto pair_range( std::pair<T,U> const& ab ) { return std::ranges::subrange { ab.first, ab.second }; }

So then we can call:

for (auto val : pair_range(data.equal_range(1))) {

Is there something wrong with either of these? It seems weird that this was not dealt with in a nice fashion, there are a lot of interfaces that return pair<It,It>, when are we going to move forward on this?

Read Entire Article