Namespaces
Variants

std:: equality_comparable, std:: equality_comparable_with

From cppreference.net
헤더에 정의됨 <concepts>
template < class T >
concept equality_comparable = __WeaklyEqualityComparableWith < T, T > ;
(1) (C++20부터)
template < class T, class U >

concept equality_comparable_with =
std :: equality_comparable < T > &&
std :: equality_comparable < U > &&
__ComparisonCommonTypeWith < T, U > &&
std :: equality_comparable <
std:: common_reference_t <
const std:: remove_reference_t < T > & ,
const std:: remove_reference_t < U > & >> &&

__WeaklyEqualityComparableWith < T, U > ;
(2) (C++20부터)
도움 개념들
template < class T, class U >

concept __WeaklyEqualityComparableWith =
requires ( const std:: remove_reference_t < T > & t,
const std:: remove_reference_t < U > & u ) {
{ t == u } - > boolean-testable ;
{ t ! = u } - > boolean-testable ;
{ u == t } - > boolean-testable ;
{ u ! = t } - > boolean-testable ;

} ;
(3) ( 설명 전용* )
(4)
template < class T, class U >

concept __ComparisonCommonTypeWith =
std:: common_reference_with <
const std:: remove_reference_t < T > & ,

const std:: remove_reference_t < U > & > ;
(C++23 이전)
( 설명 전용* )
template < class T, class U, class C = std:: common_reference_t < const T & , const U & > >

concept _ComparisonCommonTypeWithImpl =
std:: same_as < std:: common_reference_t < const T & , const U & > ,
std:: common_reference_t < const U & , const T & >> &&
requires {
requires std:: convertible_to < const T & , const C & > ||
std:: convertible_to < T, const C & > ;
requires std:: convertible_to < const U & , const C & > ||
std:: convertible_to < U, const C & > ;
} ;
template < class T, class U >
concept __ComparisonCommonTypeWith =

_ComparisonCommonTypeWithImpl < std:: remove_cvref_t < T > , std:: remove_cvref_t < U >> ;
(C++23 이후)
( 설명 전용* )
1) 개념 std::equality_comparable T 에 대한 비교 연산자 == != 가 동등성을 반영하도록 지정합니다: == 는 피연산자들이 동일한 경우에만 true 를 반환합니다.
2) std::equality_comparable_with 개념은 (혼합된) T U 피연산자에 대한 비교 연산자 == != 가 동등성과 일관된 결과를 생성하도록 지정합니다. 혼합된 피연산자를 비교하는 것은 피연산자를 공통 타입으로 변환하여 비교한 것과 동등한 결과를 생성합니다.
3) 전시 전용(exposition-only) 개념 __WeaklyEqualityComparableWith T 타입의 객체와 U 타입의 객체가 서로 동등성 비교(어느 순서로든)가 가능하며, == != 를 모두 사용하여 비교할 수 있고, 비교 결과가 일관적임을 명시합니다.
4) 설명 전용 개념 __ComparisonCommonTypeWith 는 두 타입이 공통 타입을 공유하며, const 좌측값 또는 비-const 우측값 (C++23부터) 이 해당 공통 타입으로 변환 가능함을 명시합니다.

목차

의미론적 요구사항

이러한 개념들은 해당 개념이 충족되고 그들이 포함하는 모든 개념이 모델링된 경우에만 모델링됩니다.

다음 단락들에서, 표현식 E 와 타입 C 가 주어졌을 때, CONVERT_TO < C > ( E ) 는 다음과 같이 정의됩니다:

(C++23 이전)
  • static_cast < const C & > ( std:: as_const ( E ) ) 해당 표현식이 유효한 경우,
  • static_cast < const C & > ( std :: move ( E ) ) 그렇지 않은 경우.
(C++23 이후)
1) std :: equality_comparable < T > 는 다음 조건이 충족될 때만 모델링됩니다: 타입 T 의 객체 a b 가 주어졌을 때, bool ( a == b ) true 인 경우는 오직 a b 가 동일할 때만입니다. a == b equality-preserving 이어야 한다는 요구사항과 함께, 이는 == 가 대칭적이고 추이적임을 의미하며, 더 나아가 적어도 하나의 다른 객체와 동일한 모든 객체 a 에 대해 == 가 반사적임을 의미합니다.
2) std :: equality_comparable_with < T, U > 는 다음 조건이 충족될 때만 모델링됩니다:

다음 표현식이 참이어야 합니다:

  • bool ( t == u ) == bool ( CONVERT_TO < C > ( t2 ) == CONVERT_TO < C > ( u2 ) ) .
3) __WeaklyEqualityComparableWith < T, U > 개념은 다음 조건이 충족될 때만 모델됩니다:

다음 조건들이 참이어야 합니다:

  • t == u , u == t , t ! = u , u ! = t 가 동일한 정의역을 가짐;
  • bool ( u == t ) == bool ( t == u ) ;
  • bool ( t ! = u ) == ! bool ( t == u ) ; 그리고
  • bool ( u ! = t ) == bool ( t ! = u ) .
4) __WeaklyEqualityComparableWith < T, U > 개념은 다음 조건에서만 모델됩니다:

해당하는 common_reference_with 개념이 모델된 경우.

(C++23 이전)

다음을 가정할 때:

다음 조건들이 성립해야 합니다:

  • CONVERT_TO < C > ( t1 ) CONVERT_TO < C > ( t2 ) 와 동등한 것은 t1 t2 와 동등한 경우에만 해당합니다; 그리고
  • CONVERT_TO < C > ( u1 ) CONVERT_TO < C > ( u2 ) 와 동등한 것은 u1 u2 와 동등한 경우에만 해당합니다.
(C++23 이후)

동등성 보존

표준 라이브러리 개념의 requires expressions 에 선언된 표현식들은 equality-preserving 해야 합니다(다르게 명시된 경우를 제외하고).

암시적 표현 변형

상수 lvalue 피연산자에 대해 비수정적인 표현식을 사용하는 requires expression implicit expression variations 도 요구합니다.

참고문헌

  • C++23 표준 (ISO/IEC 14882:2024):
  • 18.5.4 개념 equality_comparable [concept.equalitycomparable]
  • C++20 표준(ISO/IEC 14882:2020):
  • 18.5.3 개념 equality_comparable [concept.equalitycomparable]