Diferencia entre revisiones de «cpp/string/basic string/operator cmp»
(Traducción completa) | m (A la par con la versión en inglés de 27 de agosto de 2020) | ||
Línea 5: | Línea 5: | ||
{{dcl h | Compara dos objetos {{tt|basic_string}} }} | {{dcl h | Compara dos objetos {{tt|basic_string}} }} | ||
{{dcl rev multi | num=1 | {{dcl rev multi | num=1 | ||
− | | until1=c++ | + | | until1=c++11 | dcl1= |
template< class CharT, class Traits, class Alloc > | template< class CharT, class Traits, class Alloc > | ||
bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, | bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, | ||
Línea 20: | Línea 20: | ||
}} | }} | ||
{{dcl rev multi | num=2 | {{dcl rev multi | num=2 | ||
− | | until1=c++ | + | | until1=c++11 | dcl1= |
template< class CharT, class Traits, class Alloc > | template< class CharT, class Traits, class Alloc > | ||
bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, | bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, | ||
Línea 30: | Línea 30: | ||
}} | }} | ||
{{dcl rev multi | num=3 | {{dcl rev multi | num=3 | ||
− | | until1=c++ | + | | until1=c++11 | dcl1= |
template< class CharT, class Traits, class Alloc > | template< class CharT, class Traits, class Alloc > | ||
bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, | bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, | ||
Línea 40: | Línea 40: | ||
}} | }} | ||
{{dcl rev multi | num=4 | {{dcl rev multi | num=4 | ||
− | | until1=c++ | + | | until1=c++11 | dcl1= |
template< class CharT, class Traits, class Alloc > | template< class CharT, class Traits, class Alloc > | ||
− | bool operator | + | bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
const std::basic_string<CharT,Traits,Alloc>& rhs ); | const std::basic_string<CharT,Traits,Alloc>& rhs ); | ||
| until2=c++20 | dcl2= | | until2=c++20 | dcl2= | ||
template< class CharT, class Traits, class Alloc > | template< class CharT, class Traits, class Alloc > | ||
− | bool operator | + | bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
const std::basic_string<CharT,Traits,Alloc>& rhs ) noexcept; | const std::basic_string<CharT,Traits,Alloc>& rhs ) noexcept; | ||
}} | }} | ||
{{dcl rev multi | num=5 | {{dcl rev multi | num=5 | ||
− | | until1=c++ | + | | until1=c++11 | dcl1= |
template< class CharT, class Traits, class Alloc > | template< class CharT, class Traits, class Alloc > | ||
bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, | bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, | ||
Línea 180: | Línea 180: | ||
Si al menos un parámetro es de tipo {{lc|std::string}}, {{lc|std::wstring}}, {{lc|std::u8string}}, {{lc|std::u16string}}, o {{lc|std::u32string}}, el tipo de retorno de {{tt|1=operator<=>}} es {{lc|std::strong_ordering}}. | Si al menos un parámetro es de tipo {{lc|std::string}}, {{lc|std::wstring}}, {{lc|std::u8string}}, {{lc|std::u16string}}, o {{lc|std::u32string}}, el tipo de retorno de {{tt|1=operator<=>}} es {{lc|std::strong_ordering}}. | ||
}} | }} | ||
+ | |||
+ | ===Informes de defectos=== | ||
+ | {{dr list begin}} | ||
+ | {{dr list item|wg=lwg|dr=2064|std=C++11|before=Era inconsistente si sobrecargas que toman dos {{tt|basic_string}}s eran noexcept;<br>las sobrecargas que toman un {{tt|CharT*}} eran noexcept|after=Se hizo consistente;<br>se eliminó noexcept ya que puede ocurrir comportamiento indefinido. | ||
+ | }} | ||
+ | {{dr list end}} | ||
{{langlinks|de|en|fr|it|ja|pl|pt|ru|zh}} | {{langlinks|de|en|fr|it|ja|pl|pt|ru|zh}} |
Última revisión de 12:53 29 ago 2020
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, | (hasta C++11) | |
template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++11) (hasta C++20) | |
template< class CharT, class Traits, class Alloc > constexpr bool | (desde C++20) | |
(2) | ||
template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++11) | |
template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++11) (hasta C++20) | |
(3) | ||
template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++11) | |
template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++11) (hasta C++20) | |
(4) | ||
template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++11) | |
template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++11) (hasta C++20) | |
(5) | ||
template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++11) | |
template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++11) (hasta C++20) | |
(6) | ||
template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++14) | |
template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++14) (hasta C++20) | |
template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ | (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, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > constexpr bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, | (desde C++20) | |
template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs, | (hasta C++20) | |
(9) | ||
template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs, | (hasta C++20) | |
(10) | ||
template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs, | (hasta C++20) | |
(11) | ||
template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs, | (hasta C++20) | |
(12) | ||
template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs, | (hasta C++20) | |
(13) | ||
template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs, | (hasta C++20) | |
template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ | (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
lhs
yrhs
son iguales y cada carácter enlhs
tiene un carácter equivalente enrhs
en 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 (/*comp-cat*/) es Traits::comparison_category si es que existe, de lo contrario, std::weak_ordering. | (desde C++20) |
basic_string
.basic_string
y un array de CharT
terminado en nulo.Contenido |
[editar] Parámetros
lhs, rhs | - | Cadenas cuyo contenido hay que comparar. |
[editar] Valor de retorno
[editar] Complejidad
Lineal en el tamaño de las cadenas.
[editar] 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) |
[editar] 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_string s eran noexcept;las sobrecargas que toman un CharT* eran noexcept | Se hizo consistente; se eliminó noexcept ya que puede ocurrir comportamiento indefinido. |