Consider the usage with std::multimap
, where I am given a range of iterators:
std::unordered_multimap<std::string, MyObject> mymap;
auto& range = mymap.equal_range("some_key");
for (auto& the_pair : range)
{
}
Now, the code above does not compile, but I am using it for demonstration purposes. Is it possible to use range-based for loops with a pair of iterators like this? I don't imagine it is possible directly, so I guess my question is really about whether or not there is an adapter class in STL for this use case. I could probably write my own but this seems like a common case.
Update:
If this is not a common case and STL does not provide such a proxy or adapter for this type of usage, what is required to implement them? I was thinking that I'd need to overload the free functions begin
and end
and also define an adapter iterator class for std::pair<T,U>
. I'm just taking a conceptual stab at it, but please let me know! Thanks in advance everyone.