operator==,!=,<,<=,>,>=,<=> (std::basic_string)
|
Definiert in Header
<string>
|
||
|
Vergleiche zwei
basic_string
Objekte
|
||
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
==
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(1) |
(seit C++11 noexcept)
(seit C++20 constexpr) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
!
=
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(2) |
(bis C++20)
(noexcept seit C++11) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
<
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(3) |
(bis C++20)
(noexcept seit C++11) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
<=
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(4) |
(bis C++20)
(noexcept seit C++11) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
>
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(5) |
(bis C++20)
(noexcept seit C++11) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
>=
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(6) |
(bis C++20)
(noexcept seit C++11) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
constexpr
/*comp-cat*/
|
(7) | (seit C++20) |
|
Vergleiche ein
basic_string
-Objekt und eine nullterminierte Folge von
T
|
||
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
==
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(8) | (constexpr seit C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
==
(
const
CharT
*
lhs,
|
(9) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
!
=
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(10) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
!
=
(
const
CharT
*
lhs,
|
(11) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
<
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(12) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
<
(
const
CharT
*
lhs,
|
(13) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
<=
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(14) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
<=
(
const
CharT
*
lhs,
|
(15) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
>
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(16) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
>
(
const
CharT
*
lhs,
|
(17) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
>=
(
const
std::
basic_string
<
CharT,Traits,Alloc
>
&
lhs,
|
(18) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
bool
operator
>=
(
const
CharT
*
lhs,
|
(19) | (bis C++20) |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
constexpr
/*comp-cat*/
|
(20) | (seit C++20) |
Vergleicht den Inhalt eines Strings mit einem anderen String oder einer nullterminierten Folge von
CharT
.
Alle Vergleiche werden über die
compare()
Memberfunktion durchgeführt (die selbst definiert ist durch
Traits::compare()
):
- Zwei Zeichenketten sind gleich, wenn sowohl die Größe von lhs als auch von rhs gleich sind und jedes Zeichen in lhs ein entsprechendes Zeichen in rhs an derselben Position hat.
- Die Ordnungsvergleiche werden lexikographisch durchgeführt – der Vergleich wird von einer Funktion ausgeführt, die äquivalent zu std::lexicographical_compare oder std::lexicographical_compare_three_way (since C++20) ist.
basic_string
-Objekte.
basic_string
-Objekt und ein nullterminiertes Array von
CharT
.
|
Der Rückgabetyp der Drei-Wege-Vergleichsoperatoren ( /*comp-cat*/ ) ist Traits :: comparison_category , falls dieser qualifizierte Bezeichner existiert und einen Typ bezeichnet, andernfalls std::weak_ordering . Wenn /*comp-cat*/ kein Vergleichskategorietyp ist, ist das Programm fehlerhaft.
Die Operatoren
|
(seit C++20) |
Inhaltsverzeichnis |
Parameter
| lhs, rhs | - | Zeichenketten, deren Inhalte verglichen werden sollen |
Rückgabewert
Komplexität
Linear in der Größe der Strings.
Hinweise
|
Wenn mindestens ein Parameter vom Typ
std::string
,
std::wstring
,
std::u8string
,
std::u16string
oder
std::u32string
ist, ist der Rückgabetyp von
|
(since C++20) |
Beispiel
|
Dieser Abschnitt ist unvollständig
Grund: Kein Beispiel |
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrigiertes Verhalten |
|---|---|---|---|
| LWG 2064 | C++11 |
ob Überladungen mit zwei
basic_string
s noexcept sind, war inkonsistent;
Überladungen mit einem
CharT*
waren noexcept, konnten aber UB auslösen
|
konsistent gemacht;
noexcept entfernt |
| LWG 3432 | C++20 |
der Rückgabetyp von
operator<=>
musste kein Vergleichskategorietyp sein
|
erforderlich gemacht |