| template< /*different-from*/<subrange> PairLike > requires /*pair-like-convertible-from*/<PairLike, const I&, const S&> constexpr operator PairLike() const; |
(1) | (since C++20) |
| Helper concepts |
||
template< class T > concept /*pair-like*/ = /* see description */; |
(2) | (exposition only*) |
template< class T, class U, class V > concept /*pair-like-convertible-from*/ = /* see description */; |
(3) | (exposition only*) |
subrange to a pair-like type.different-from .|
Equivalent to: |
(until C++23) |
|
This concept is equivalent to the library-wide exposition-only concept |
(since C++23) |
|
Equivalent to: |
(until C++23) |
|
Equivalent to: |
(since C++23) |
Return value
Notes
Following types in the standard library are pair-like:
- std::pair<T, U>
- std::tuple<T, U>
- std::array<T, 2>
- std::ranges::subrange<I, S, K>
|
(since C++26) |
|
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.
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});
}
}A B C D E
A B C D
A B C
A B
ASee also
| (C++23) |
specifies that a type implemented the tuple protocol ( std::get, std::tuple_element, std::tuple_size)(exposition-only concept*) |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.