operator==,!=,<,<=,>,>=,<=>(std::basic_string)
| Definiert in Header <string> |
||
| Vergleicht zwei basic_string Objekte |
||
| template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(1) | (noexcept seit C++11) (constexpr seit C++20) |
| 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) |
| Vergleicht einen basic_string mit einem Null-terminierten Array 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 einem Null-terminierten Array von CharT.
Alle Vergleiche erfolgen über die Memberfunktion compare() (die selbst in Bezug auf Traits::compare() definiert ist)
- Zwei Strings sind gleich, wenn sowohl die Größe von lhs als auch rhs gleich ist und jedes Zeichen in lhs ein äquivalentes Zeichen in rhs an derselben Position hat.
- Die Ordnungsvergleiche erfolgen lexikographisch – der Vergleich wird durch eine Funktion durchgeführt, die äquivalent zu std::lexicographical_compare istoder std::lexicographical_compare_three_way(seit C++20).
basic_string Objekte.basic_string Objekt und ein Null-terminiertes Array von CharT.|
Der Rückgabetyp von Drei-Wege-Vergleichsoperatoren (/*comp-cat*/) ist Traits::comparison_category, wenn dieser qualifizierte Bezeichner existiert und einen Typ bezeichnet, andernfalls std::weak_ordering. Wenn /*comp-cat*/ kein Vergleichskategoriatyp ist, ist das Programm fehlerhaft. Die Operatoren |
(seit C++20) |
Inhalt |
[bearbeiten] Parameter
| lhs, rhs | - | Strings, deren Inhalte verglichen werden sollen |
[bearbeiten] Rückgabewert
[bearbeiten] Komplexität
Linear in der Größe der Strings.
[bearbeiten] Hinweise
|
Wenn mindestens ein Parameter vom Typ std::string, std::wstring, std::u8string, std::u16string oder std::u32string ist, ist der Rückgabetyp von |
(seit C++20) |
[bearbeiten] Beispiel
| Dieser Abschnitt ist unvollständig Grund: kein Beispiel |
[bearbeiten] 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, die zwei basic_strings nehmen, noexcept sind, war inkonsistent;Überladungen, die einen CharT* nehmen, waren noexcept, könnten aber UB auslösen |
wurde konsistent gemacht; noexcept entfernt |
| LWG 3432 | C++20 | Der Rückgabetyp von operator<=> musste kein Vergleichskategoriatyp sein |
Gefordert |