std::ranges::subrange<I,S,K>::operator PairLike
Min standard notice:
- Converts subrange to a pair-like type.
# Declarations
template< /*different-from*/<subrange> PairLike >
requires /*pair-like-convertible-from*/<PairLike, const I&, const S&>
constexpr operator PairLike() const;
(since C++20)
Helper concepts
template< class T >
concept /*pair-like*/ = /* see description */;
(exposition only*)
template< class T, class U, class V >
concept /*pair-like-convertible-from*/ = /* see description */;
(exposition only*)
# Return value
# Notes
Following types in the standard library are pair-like:
A program-defined type derived from one of these types can be a pair-like type, if
Since subrange specializations are range types, conversion to them are not performed via this conversion function.
std::array specializations cannot be converted from subrange, since they are range types.
# Example
#include <iostream>
#include <ranges>
#include <string>
#include <utility>
using striter = std::string::const_iterator;
using legacy_strview = std::pair<striter, striter>;
void legacy_print(legacy_strview p)
{
for (; p.first != p.second; ++p.first)
std::cout << *p.first << ' ';
std::cout << '\n';
}
int main()
{
std::string dat{"ABCDE"};
for (auto v{std::ranges::subrange{dat}}; v; v = {v.begin(), v.end() - 1})
{
/*...*/
legacy_print(legacy_strview{v});
}
}