operator==,!=,<,<=,>,>=,<=> (std::pair)
|
Definiert im Header
<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 ) ; |
(bis C++14) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
==
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(seit 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 ) ; |
(bis C++14) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
!
=
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(seit C++14)
(bis 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 ) ; |
(bis C++14) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
<
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(seit C++14)
(bis 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 ) ; |
(bis C++14) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
<=
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(seit C++14)
(bis 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 ) ; |
(bis C++14) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
>
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(seit C++14)
(bis 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 ) ; |
(bis C++14) | |
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
bool
operator
>=
(
const
std::
pair
<
T1, T2
>
&
lhs,
|
(seit C++14)
(bis C++20) |
|
|
template
<
class
T1,
class
T2,
class
U1,
class
U2
>
constexpr
std::
common_comparison_category_t
<
synth
-
three
-
way
-
result
<
T1, U1
>
,
|
(7) | (seit C++20) |
|
Das Verhalten ist undefiniert, wenn Typ und Wertkategorie von entweder lhs. first == rhs. first oder lhs. second == rhs. second die BooleanTestable -Anforderungen nicht erfüllen. |
(bis C++26) |
|
Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn sowohl
decltype
(
lhs.
first
==
rhs.
first
)
als auch
decltype
(
lhs.
second
==
rhs.
second
)
das Konzept
|
(seit C++26) |
synth-three-way
.
|
Die Operatoren
|
(seit C++20) |
Inhaltsverzeichnis |
Parameter
| lhs, rhs | - | zu vergleichende Paare |
Rückgabewert
Hinweise
|
Die relationalen Operatoren werden anhand des operator < jedes Elements definiert. |
(bis C++20) |
|
Die relationalen Operatoren werden anhand von synth-three-way definiert, das operator <=> verwendet, falls möglich, andernfalls operator < . Insbesondere, wenn ein Elementtyp selbst keinen operator <=> bereitstellt, aber implizit in einen dreiweg-vergleichbaren Typ konvertierbar ist, wird diese Konvertierung anstelle von operator < verwendet. |
(seit C++20) |
| Feature-Test Makro | Wert | Std | Funktion |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202403L
|
(C++26) | Eingeschränkter operator == für std::pair |
Beispiel
Da operator < für Paare definiert ist, können Container von Paaren sortiert werden.
#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"; }
Ausgabe:
{1, "foo"}
{2, "bar"}
{2, "baz"}
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrektes Verhalten |
|---|---|---|---|
| LWG 296 | C++98 |
die Beschreibungen der Operatoren außer
==
und
<
fehlten
|
hinzugefügt |
|
LWG 2114
( P2167R3 ) |
C++98 | Typ-Vorbedingungen für boolesche Operationen fehlten | hinzugefügt |
| LWG 3865 | C++98 |
Vergleichsoperatoren akzeptierten nur
pair
s desselben Typs
|
akzeptieren
pair
s verschiedener Typen
|
Siehe auch
|
(entfernt in C++20)
(entfernt in C++20)
(entfernt in C++20)
(entfernt in C++20)
(entfernt in C++20)
(C++20)
|
vergleicht die Werte im Tupel lexikographisch
(Funktions-Template) |