operator==,!=,<,<=,>,>=,<=>(std::basic_string)
De cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| Definido en el archivo de encabezado <string>
|
||
| Compara dos objetos basic_string |
||
| (1) | ||
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 ); |
(hasta 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 ) noexcept; |
(desde C++11) (hasta C++20) |
|
template< class CharT, class Traits, class Alloc > constexpr bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ) noexcept; |
(desde C++20) | |
| (2) | ||
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 ); |
(hasta 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 ) noexcept; |
(desde C++11) (hasta C++20) |
|
| (3) | ||
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 ); |
(hasta 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 ) noexcept; |
(desde C++11) (hasta C++20) |
|
| (4) | ||
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 ); |
(hasta 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 ) noexcept; |
(desde C++11) (hasta C++20) |
|
| (5) | ||
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 ); |
(hasta 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 ) noexcept; |
(desde C++11) (hasta C++20) |
|
| (6) | ||
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 ); |
(hasta C++14) | |
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 ) noexcept; |
(desde C++14) (hasta C++20) |
|
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) | (desde C++20) |
| Compara un objeto basic_string y un array de T terminado en nulo |
||
| (8) | ||
template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > constexpr bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(desde C++20) | |
template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ); |
(hasta C++20) | |
| (9) | ||
template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ); |
(hasta C++20) | |
| (10) | ||
template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ); |
(hasta C++20) | |
| (11) | ||
template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ); |
(hasta C++20) | |
| (12) | ||
template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ); |
(hasta C++20) | |
| (13) | ||
template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs, const std::basic_string<CharT,Traits,Alloc>& rhs ); |
(hasta C++20) | |
template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); |
(14) | (desde C++20) |
Compara el contenido de una cadena con otra cadena o un array de CharT terminado en nulo.
Todas las comparaciones se hacen mediante la función miembro compare() (que en sí misma se define en términos de Traits::compare()):
- Dos cadenas son iguales si tanto el tamaño de
lhsyrhsson iguales y cada carácter enlhstiene un carácter equivalente enrhsen la misma posición.
- El orden de las comparaciones se hace lexicográficamente--la comparación se realiza por una función equivalente a std::lexicographical_compare o std::lexicographical_compare_three_way (desde C++20).
|
El tipo de retorno de los operadores de comparación de tres vías ( |
(desde C++20) |
1-7) Compara dos objetos
basic_string.8-14) Compara un objeto
basic_string y un array de CharT terminado en nulo.Parámetros
| lhs, rhs | - | Cadenas cuyo contenido hay que comparar. |
Valor de retorno
1-6,8-13)
true si se mantiene la comparación correspondiente, de lo contrario, false.7,14)
static_cast</*comp-cat*/>(lhs.compare(rhs) <=> 0).Complejidad
Lineal en el tamaño de las cadenas.
Notas
|
Si al menos un parámetro es de tipo std::string, std::wstring, std::u8string, std::u16string, o std::u32string, el tipo de retorno de |
(desde C++20) |
Informes de defectos
Los siguientes informes de defectos de cambio de comportamiento se aplicaron de manera retroactiva a los estándares de C++ publicados anteriormente.
| ID | Aplicado a | Comportamiento según lo publicado | Comportamiento correcto |
|---|---|---|---|
| LWG 2064 | C++11 | Era inconsistente si sobrecargas que toman dos basic_strings eran noexcept;las sobrecargas que toman un CharT* eran noexcept
|
Se hizo consistente; se eliminó noexcept ya que puede ocurrir comportamiento indefinido. |