std::three_way_comparable, std::three_way_comparable_with
| 헤더 <compare>
|
||
template< class T, class Cat = std::partial_ordering >
concept three_way_comparable =
__WeaklyEqualityComparableWith<T, T> &&
__PartiallyOrderedWith<T, T> &&
requires(const std::remove_reference_t<T>& a,
const std::remove_reference_t<T>& b) {
{ a <=> b } -> __ComparesAs<Cat>;
};
|
에 정의됨 (1) | (C++20 이후) |
template< class T, class U, class Cat = std::partial_ordering >
concept three_way_comparable_with =
std::three_way_comparable<T, Cat> &&
std::three_way_comparable<U, Cat> &&
__ComparisonCommonTypeWith<T, U> &&
std::three_way_comparable<
std::common_reference_t<
const std::remove_reference_t<T>&,
const std::remove_reference_t<U>&>, Cat> &&
__WeaklyEqualityComparableWith<T, U> &&
__PartiallyOrderedWith<T, U> &&
requires(const std::remove_reference_t<T>& t,
const std::remove_reference_t<U>& u) {
{ t <=> u } -> __ComparesAs<Cat>;
{ u <=> t } -> __ComparesAs<Cat>;
};
|
(2) | (C++20 이후) |
template< class T, class Cat >
concept __ComparesAs =
std::same_as<std::common_comparison_category_t<T, Cat>, Cat>;
|
(3) | (설명 전용*) |
std::three_way_comparable는 삼방 비교 연산자 <=>가 T에 대해 Cat이 암시하는 비교 범주와 일관된 결과를 산출함을 명시합니다.std::three_way_comparable_with는 삼방 비교 연산자 <=>가 (혼합될 수 있는) T 및 U 피연산자에 대해 Cat이 암시하는 비교 범주와 일관된 결과를 산출함을 명시합니다. 혼합 피연산자를 비교하는 것은 피연산자를 공통 타입으로 변환하여 비교한 결과와 동등한 결과를 산출합니다.__WeaklyEqualityComparableWith, __PartiallyOrderedWith, 및 __ComparisonCommonTypeWith는 설명 전용 개념입니다. equality_comparable 및 totally_ordered의 설명을 참조하십시오.
의미론적 요구사항
이러한 개념들은 해당 개념이 충족되고 그들이 포함하는 모든 개념이 모델링된 경우에만 모델링됩니다.
T
와
Cat
이 다음 조건을 만족할 때만
std
::
three_way_comparable
<
T, Cat
>
개념을 모델합니다: 타입
const
std::
remove_reference_t
<
T
>
의 lvalue
a
와
b
가 주어졌을 때 다음이 참이어야 합니다:
- ( a <=> b == 0 ) == bool ( a == b ) ,
- ( a <=> b ! = 0 ) == bool ( a ! = b ) ,
- ( ( a <=> b ) <=> 0 ) 와 ( 0 <=> ( b <=> a ) ) 가 동일하며,
- bool ( a > b ) == bool ( b < a ) ,
- bool ( a >= b ) == ! bool ( a < b ) ,
- bool ( a <= b ) == ! bool ( b < a ) ,
- ( a <=> b < 0 ) == bool ( a < b ) ,
- ( a <=> b > 0 ) == bool ( a > b ) ,
- ( a <=> b <= 0 ) == bool ( a <= b ) , 그리고
- ( a <=> b >= 0 ) == bool ( a >= b ) , 그리고
-
만약
Cat이 std::strong_ordering 으로 변환 가능하다면,T는totally_ordered개념을 모델합니다.
T
,
U
, and
Cat
model
std
::
three_way_comparable_with
<
T, U, Cat
>
only if given
-
t와t2, 각각 const std:: remove_reference_t < T > 및 std:: remove_reference_t < T > 타입의 서로 다른 동등한 객체를 나타내는 lvalue들, 그리고 -
u와u2, 각각 const std:: remove_reference_t < U > 및 std:: remove_reference_t < U > 타입의 서로 다른 동등한 객체를 나타내는 lvalue들.
C
를
std::
common_reference_t
<
const
std::
remove_reference_t
<
T
>
&
,
const
std::
remove_reference_t
<
U
>
&
>
라 하고, 표현식
E
와 타입
C
가 주어졌을 때,
CONVERT_TO
<
C
>
(
E
)
를 다음과 같이 정의한다:
|
(C++23 이전) |
|
(C++23 이후) |
다음은 참입니다:
- t <=> u 와 u <=> t 는 동일한 정의역을 가집니다,
- ( ( t <=> u ) <=> 0 ) 와 ( 0 <=> ( u <=> t ) ) 는 동일합니다,
- ( t <=> u == 0 ) == bool ( t == u ) ,
- ( t <=> u ! = 0 ) == bool ( t ! = u ) ,
- Cat ( t <=> u ) == Cat ( CONVERT_TO < C > ( t2 ) <=> CONVERT_TO < C > ( u2 ) ) ,
- ( t <=> u < 0 ) == bool ( t < u ) ,
- ( t <=> u > 0 ) == bool ( t > u ) ,
- ( t <=> u <= 0 ) == bool ( t <= u ) ,
- ( t <=> u >= 0 ) == bool ( t >= u ) , 그리고
-
만약
Cat이 std::strong_ordering 으로 변환 가능하다면,T와U는 std:: totally_ordered_with < T, U > 를 만족합니다.
동등성 보존
표준 라이브러리 개념의 requires expressions 에 선언된 표현식들은 equality-preserving 해야 합니다(다르게 명시된 경우를 제외하고).
암시적 표현 변형
상수 lvalue 피연산자에 대해 비수정적인 표현식을 사용하는 requires expression 는 암시적 표현식 변형 도 요구합니다.
참고 항목
==
연산자가 동치 관계임을 명시함
(concept) |
|
|
해당 타입의 비교 연산자들이 전순서를 생성함을 명시함
(concept) |