subrange
to a pair-like type (i.e. a type models the helper concept pair-like
defined below (until C++23)pair-like
(since C++23)). Equivalent to return PairLike(i_, s_);
, where i_
and s_
are the stored iterator and sentinel respectively.pair-like-convertible
(see below).pair-like
specifies a type is pair-like. Generally, an expression e
of a pair-like type can be used for structured binding (i.e. auto const& [x, y] = e;
is generally well-formed). This concept is replaced by the library-wide exposition-only concept pair-like
. (since C++23)
pair-like-convertible-from
refines pair-like
. It range
types, U
and V
are convertible to the first and second element type of T
respectively, and U
(which will be replaced by const I&
) to the first element type to be non-slicing (see convertible-to-non-slicing
).(none).
A PairLike
value direct-initialized with the stored iterator and sentinel.
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.
| (until C++23) |
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.
#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}); } }
Output:
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/subrange/operator_PairLike