operator==,!=,<,<=,>,>=,<=> (std::vector)
|
Definiert im Header
<vector>
|
||
|
template
<
class
T,
class
Alloc
>
bool
operator
==
(
const
std::
vector
<
T, Alloc
>
&
lhs,
|
(1) | (constexpr seit C++20) |
|
template
<
class
T,
class
Alloc
>
bool
operator
!
=
(
const
std::
vector
<
T, Alloc
>
&
lhs,
|
(2) | (bis C++20) |
|
template
<
class
T,
class
Alloc
>
bool
operator
<
(
const
std::
vector
<
T, Alloc
>
&
lhs,
|
(3) | (bis C++20) |
|
template
<
class
T,
class
Alloc
>
bool
operator
<=
(
const
std::
vector
<
T, Alloc
>
&
lhs,
|
(4) | (bis C++20) |
|
template
<
class
T,
class
Alloc
>
bool
operator
>
(
const
std::
vector
<
T, Alloc
>
&
lhs,
|
(5) | (bis C++20) |
|
template
<
class
T,
class
Alloc
>
bool
operator
>=
(
const
std::
vector
<
T, Alloc
>
&
lhs,
|
(6) | (bis C++20) |
|
template
<
class
T,
class
Alloc
>
constexpr
/* siehe unten */
|
(7) |
(seit C++20)
(constexpr seit C++20) |
Vergleicht die Inhalte zweier
vector
s.
Sei
value_type
der Werttyp von
vector
(d.h.,
typename
vector
::
value_type
):
|
return
std::
distance
(
lhs.
begin
(
)
, lhs.
end
(
)
)
|
(bis C++14) |
|
return std:: equal ( lhs. begin ( ) , lhs. end ( ) , rhs. begin ( ) , rhs. end ( ) ) ; |
(seit C++14) |
rhs. begin ( ) , rhs. end ( ) ) ; .
-
value_typeist nicht LessThanComparable . - operator < stellt keine Totalordnung her.
rhs.
begin
(
)
, rhs.
end
(
)
,
synth-three-way
)
.
-
Terfüllt nicht die Anforderungen vonthree_way_comparable. -
operator
<
ist nicht für Werte des Typs (möglicherweise const-qualifiziert)
value_typedefiniert. - operator < etabliert keine Totalordnung .
|
Die Operatoren
|
(seit C++20) |
Inhaltsverzeichnis |
Parameter
| lhs, rhs | - |
vector
s, deren Inhalte verglichen werden sollen
|
Rückgabewert
| Operator |
lhs
und
rhs
sind gleich |
lhs
ist
lexikografisch größer |
rhs
ist
lexikografisch größer |
|---|---|---|---|
| operator == | true | false | |
| operator ! = | false | true | |
| operator < | false | false | true |
| operator <= | true | ||
| operator > | false | true | false |
| operator >= | true | ||
| operator <=> | ein Wert gleich 0 | ein Wert größer als 0 | ein Wert kleiner als 0 |
Komplexität
vector
.
vector
.
Hinweise
|
Die relationalen Operatoren sind definiert in Bezug auf
|
(bis C++20) |
|
Die relationalen Operatoren sind nicht definiert. Der umgeschriebene Kandidat operator <=> wird durch Überladungsauflösung ausgewählt.
operator
<=>
verwendet
|
(seit C++20) |
Beispiel
#include <cassert> #include <compare> #include <vector> int main() { const std::vector a{1, 2, 3}, b{1, 2, 3}, c{7, 8, 9, 10}; assert ("" "Vergleiche gleiche Container:" && (a != b) == false && (a == b) == true && (a < b) == false && (a <= b) == true && (a > b) == false && (a >= b) == true && (a <=> b) != std::weak_ordering::less && (a <=> b) != std::weak_ordering::greater && (a <=> b) == std::weak_ordering::equivalent && (a <=> b) >= 0 && (a <=> b) <= 0 && (a <=> b) == 0 && "Vergleiche ungleiche Container:" && (a != c) == true && (a == c) == false && (a < c) == true && (a <= c) == true && (a > c) == false && (a >= c) == false && (a <=> c) == std::weak_ordering::less && (a <=> c) != std::weak_ordering::equivalent && (a <=> c) != std::weak_ordering::greater && (a <=> c) < 0 && (a <=> c) != 0 && (a <=> c) <= 0 && ""); }
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 3431 | C++20 |
operator
<=>
erforderte nicht, dass
T
das Konzept
three_way_comparable
modelliert
|
erfordert |