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 要件を満たさない場合、動作は未定義である。 |
(C++26以前) |
|
このオーバーロードは、
decltype
(
lhs.
first
==
rhs.
first
)
と
decltype
(
lhs.
second
==
rhs.
second
)
の両方が
|
(C++26以降) |
synth-three-way
の戻り値の型です。
|
|
(C++20以降) |
目次 |
パラメータ
| lhs, rhs | - | 比較対象のペア |
戻り値
注記
|
関係演算子は各要素の operator < を用いて定義される。 |
(C++20まで) |
|
関係演算子は synth-three-way を用いて定義され、これは可能な場合は operator <=> を、そうでない場合は operator < を使用する。 特に、要素型自体が operator <=> を提供しないが、三方比較可能な型に暗黙変換可能な場合、その変換が operator < の代わりに使用される。 |
(C++20以降) |
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202403L
|
(C++26) | 制約付き operator == を std::pair に追加 |
例
operator < がペアに対して定義されているため、ペアのコンテナをソートすることができます。
#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)
|
タプル内の値を辞書順に比較する
(関数テンプレート) |