operator==,!=,<,<=,>,>=,<=>(std::basic_string)
| Défini dans l'en-tête <string>
|
||
| Compare deux objets basic_string |
||
template< class CharT, class Traits, class Alloc >
bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(1) | (noexcept depuis C++11) (constexpr depuis C++20) |
template< class CharT, class Traits, class Alloc >
bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(2) | (jusqu'à C++20) (noexcept depuis C++11) |
template< class CharT, class Traits, class Alloc >
bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(3) | (jusqu'à C++20) (noexcept depuis C++11) |
template< class CharT, class Traits, class Alloc >
bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(4) | (jusqu'à C++20) (noexcept depuis C++11) |
template< class CharT, class Traits, class Alloc >
bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(5) | (jusqu'à C++20) (noexcept depuis C++11) |
template< class CharT, class Traits, class Alloc >
bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(6) | (jusqu'à C++20) (noexcept depuis C++11) |
template< class CharT, class Traits, class Alloc >
constexpr /*comp-cat*/
operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs ) noexcept;
|
(7) | (depuis C++20) |
| Compare un objet basic_string et un tableau terminé par un caractère nul de T |
||
template< class CharT, class Traits, class Alloc >
bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(8) | (constexpr depuis C++20) |
template< class CharT, class Traits, class Alloc >
bool operator==( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(9) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(10) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator!=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(11) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(12) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(13) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(14) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(15) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(16) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(17) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(18) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(19) | (jusqu'à C++20) |
template< class CharT, class Traits, class Alloc >
constexpr /*comp-cat*/
operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(20) | (depuis C++20) |
Compare le contenu d'une chaîne avec une autre chaîne ou un tableau terminé par un caractère nul de CharT.
Toutes les comparaisons se font via la fonction membre compare() (qui elle-même est définie en termes de Traits::compare()):
- Deux chaînes sont égales si la taille de
lhset derhssont égales et si chaque caractère danslhsa un caractère équivalent dansrhsà la même position.
- Les comparaisons d'ordre sont effectuées lexicographiquement – la comparaison est effectuée par une fonction équivalente à std::lexicographical_compareou std::lexicographical_compare_three_way(depuis C++20).
basic_string.basic_string et un tableau terminé par un caractère nul de CharT.|
Le type de retour des opérateurs de comparaison à trois voies ( Les opérateurs |
(depuis C++20) |
Paramètres
| lhs, rhs | - | chaînes dont le contenu doit être comparé |
Valeur de retour
Complexité
Linéaire dans la taille des chaînes de caractères.
Notes
|
Si au moins un paramètre est de type
std::string
,
std::wstring
,
std::u8string
,
std::u16string
, ou
std::u32string
, le type de retour de
|
(depuis C++20) |
Exemple
|
Cette section est incomplète
Raison : aucun exemple |
Rapports de défauts
Les rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.
| DR | Appliqué à | Comportement publié | Comportement corrigé |
|---|---|---|---|
| LWG 2064 | C++11 |
la spécification noexcept des surcharges prenant deux
basic_string
était incohérente ;
les surcharges prenant un
CharT*
étaient noexcept mais pouvaient causer un comportement indéfini
|
rendu cohérent ;
noexcept supprimé |
| LWG 3432 | C++20 |
le type de retour de
operator<=>
n'était pas requis d'être un type de catégorie de comparaison
|
requis |