ARTICLE AD BOX
In C++11, std::pair very specifically did not work with range-based for loops or offer begin() and end() methods.
C++20 has gained much more support for "ranges", so you are now expected to have values you are passing around that satisfy the std::ranges::range concept, and represent something you can iterate that might not itself be a collection. As I understand it, an std::pair of two iterators intentionally does not satisfy std::ranges::range, just like it isn't usable in a range-based for loop.
It seems like std::ranges::subrange is the Right Type to use for representing a range with a pair of iterators. But older code may still use std::pair for this.
I'm looking for the Right Way to bridge the gap and pass an std::pair of two of the same iterator type to newer code that expects a range. I need this to be:
An expression: I don't want to destructure the pair into two variables and then use the variables to build an std::ranges::subrange. I want this to all fit in the argument of e.g. std::ranges::for_each. Able to use return values of other expressions: std::ranges::subrange(pair.first, pair.second) needs to name the pair twice, so if the pair comes from a function call I'd need to call the function twice. I need something where the expression for the pair to convert appears only once. As succinct as possible where used: I think Boost might have something that can do this, but I think it has a fairly long name. Ideally, I would provide some kind of conversion implementation that overrules the standards committee and declares at least some std::pairs to satisfy or implicitly convert to something that satisfies std::ranges::range. But a range-ification function or constructor with a short name would also be acceptable.If there's something built into the STL somewhere, that would be best. Something from Boost might also work, as would something where I have to actually include an implementation in my code.
