From cppreference.com
template</*different-from*/<subrange>PairLike>requires/*pair-like-convertible-from*/<PairLike,constI&,constS&>constexproperatorPairLike()const; (1) (since C++20)Helper concepts
template<classT>concept/*pair-like*/=/* see description */; (2)(exposition only*)template<classT,classU,classV>concept/*pair-like-convertible-from*/=/* see description */; (3)(exposition only*)1) Converts subrange to a pair-like type.
For the definition of /*different-from*/, see
.
2) Determines whether a type is pair-like .
Equivalent to:
template<classT>concept/*pair-like*/=!std::is_reference_v<T>&&requires(Tt){typenamestd::tuple_size<T>::type;requiresstd::derived_from<std::tuple_size<T>,std::integral_constant<std::size_t,2>>;typenamestd::tuple_element_t<0,std::remove_const_t<T>>;typenamestd::tuple_element_t<1,std::remove_const_t<T>>;{std::get<0>(t)}->std::convertible_to<conststd::tuple_element_t<0,T>&>;{std::get<1>(t)}->std::convertible_to<conststd::tuple_element_t<1,T>&>;};(until C++23)This concept is equivalent to the library-wide exposition-only concept
.
(since C++23)3) Determines whether a pair-like type can be constructed from two values of possibly different given types.
Equivalent to:
template<classT,classU,classV>concept/*pair-like-convertible-from*/=!ranges::range<T>&&/*pair-like*/<T>&&std::constructible_from<T,U,V>&&/*convertible-to-non-slicing*/<U,std::tuple_element_t<0,T>>&&std::convertible_to<V,std::tuple_element_t<1,T>>;(until C++23)Equivalent to:
template<classT,classU,classV>concept/*pair-like-convertible-from*/=!ranges::range<T>&&!std::is_reference_v<T>&&/*pair-like*/<T>&&std::constructible_from<T,U,V>&&/*convertible-to-non-slicing*/<U,std::tuple_element_t<0,T>>&&std::convertible_to<V,std::tuple_element_t<1,T>>;(since C++23)Return value
PairLike(
,
)
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>
std::complex<T>
(since C++26)A program-defined type derived from one of these types can be a pair-like type, if
and
are correctly specialized for it, and
calls to std::get<0> and std::get<1> for its value are well-formed.
(until C++23)Since subrange specializations are
types, conversion to them are not performed via this conversion function.
specializations cannot be converted from subrange, since they are
types.
Example
Run this code
#include<iostream>#include<ranges>#include<string>#include<utility>usingstriter=std::string::const_iterator;usinglegacy_strview=std::pair<striter,striter>;voidlegacy_print(legacy_strviewp){for(;p.first!=p.second;++p.first)std::cout<<*p.first<<' ';std::cout<<'\n';}intmain(){std::stringdat{"ABCDE"};for(autov{std::ranges::subrange{dat}};v;v={v.begin(),v.end()-1}){/*...*/legacy_print(legacy_strview{v});}}Output:
A B C D E A B C D A B C A B A See also