operator==,!=,<,<=,>,>=,<=> (std::pair)
|
헤더에 정의됨
<utility>
|
||
| (1) | ||
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
bool operator == ( const std:: pair < T1, T2 > & lhs, const std:: pair < U1, U2 > & rhs ) ; |
(C++14 이전) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
==
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(C++14 이후) | |
| (2) | ||
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
bool operator ! = ( const std:: pair < T1, T2 > & lhs, const std:: pair < U1, U2 > & rhs ) ; |
(C++14 이전) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
!
=
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(C++14 이후)
(C++20 이전) |
|
| (3) | ||
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
bool operator < ( const std:: pair < T1, T2 > & lhs, const std:: pair < U1, U2 > & rhs ) ; |
(C++14 이전) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
<
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(C++14 이후)
(C++20 이전) |
|
| (4) | ||
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
bool operator <= ( const std:: pair < T1, T2 > & lhs, const std:: pair < U1, U2 > & rhs ) ; |
(C++14 이전) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
<=
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(C++14 이후)
(C++20 이전) |
|
| (5) | ||
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
bool operator > ( const std:: pair < T1, T2 > & lhs, const std:: pair < U1, U2 > & rhs ) ; |
(C++14 이전) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
>
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(C++14 이후)
(C++20 이전) |
|
| (6) | ||
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
bool operator >= ( const std:: pair < T1, T2 > & lhs, const std:: pair < U1, U2 > & rhs ) ; |
(C++14 이전) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
>=
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(C++14 이후)
(C++20 이전) |
|
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
std::
common_comparison_category_t
<
synth
-
three
-
way
-
result
<
T1, U1
>
,
|
(7) | (C++20부터) |
|
lhs. first == rhs. first 또는 lhs. second == rhs. second 중 하나의 타입과 값 카테고리가 BooleanTestable 요구 사항을 충족하지 않는 경우 동작은 정의되지 않습니다. |
(until C++26) |
|
이 오버로드는
decltype
(
lhs.
first
==
rhs.
first
)
와
decltype
(
lhs.
second
==
rhs.
second
)
모두가
|
(since C++26) |
synth-three-way
의 반환 타입입니다.
|
|
(C++20부터) |
목차 |
매개변수
| lhs, rhs | - | 비교할 쌍 |
반환값
참고 사항
|
관계 연산자는 각 요소의 operator < 를 기반으로 정의됩니다. |
(C++20까지) |
|
관계 연산자는 synth-three-way 를 기반으로 정의되며, 이는 가능한 경우 operator <=> 를 사용하고, 그렇지 않으면 operator < 를 사용합니다. 특히, 요소 타입 자체가 operator <=> 를 제공하지 않지만 three-way 비교 가능 타입으로 암시적으로 변환 가능한 경우, operator < 대신 해당 변환이 사용됩니다. |
(C++20부터) |
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202403L
|
(C++26) | 제약된 operator == for std::pair |
예제
operator < 가 pair에 대해 정의되어 있으므로, pair의 컨테이너를 정렬할 수 있습니다.
#include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <utility> #include <vector> int main() { std::vector<std::pair<int, std::string>> v = {{2, "baz"}, {2, "bar"}, {1, "foo"}}; std::sort(v.begin(), v.end()); for (auto p : v) std::cout << '{' << p.first << ", " << std::quoted(p.second) << "}\n"; }
출력:
{1, "foo"}
{2, "bar"}
{2, "baz"}
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 296 | C++98 |
==
및
<
이외의
연산자 설명이 누락됨
|
추가됨 |
|
LWG 2114
( P2167R3 ) |
C++98 | 불린 연산에 대한 타입 전제조건이 누락됨 | 추가됨 |
| LWG 3865 | C++98 |
비교 연산자가 동일한 타입의
pair
만
허용함
|
서로 다른 타입의
pair
를 허용함
|
참고 항목
|
(C++20에서 제거됨)
(C++20에서 제거됨)
(C++20에서 제거됨)
(C++20에서 제거됨)
(C++20에서 제거됨)
(C++20)
|
튜플 내의 값들을 사전식으로 비교
(함수 템플릿) |