operator==,!=,<,<=,>,>=, <=> (std::basic_string)
Определено в заголовке <string> |
||
|---|---|---|
Сравнение двух объектов 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 ); |
(до 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;
|
(с C++11) (до 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;
|
(с 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 ); |
(до 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;
|
(с C++11) (до 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 ); |
(до 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;
|
(с C++11) (до 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 ); |
(до 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;
|
(с C++11) (до 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 ); |
(до 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;
|
(с C++11) (до 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 ); |
(до 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;
|
(с C++11) (до 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) | (с C++20) |
Сравнение объекта basic_string и строки с нулевым окончанием T
|
||
| (8) | ||
template< class CharT, class Traits, class Alloc >
bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs ); |
(до C++20) | |
template< class CharT, class Traits, class Alloc >
constexpr bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(с C++20) | |
template< class CharT, class Traits, class Alloc >
bool operator==( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(до C++20) | |
| (9) | ||
template< class CharT, class Traits, class Alloc >
bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs ); |
(до C++20) | |
template< class CharT, class Traits, class Alloc >
bool operator!=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(до C++20) | |
| (10) | ||
template< class CharT, class Traits, class Alloc >
bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs ); |
(до C++20) | |
template< class CharT, class Traits, class Alloc >
bool operator<( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(до C++20) | |
| (11) | ||
template< class CharT, class Traits, class Alloc >
bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs ); |
(до C++20) | |
template< class CharT, class Traits, class Alloc >
bool operator<=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(до C++20) | |
| (12) | ||
template< class CharT, class Traits, class Alloc >
bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs ); |
(до C++20) | |
template< class CharT, class Traits, class Alloc >
bool operator>( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(до C++20) | |
| (13) | ||
template< class CharT, class Traits, class Alloc >
bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs ); |
(до C++20) | |
template< class CharT, class Traits, class Alloc >
bool operator>=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(до 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) | (с C++20) |
Сравнивает содержимое строки с другой строкой или строкой с нулевым окончанием CharT.
Все сравнения выполняются с помощью функции-члена compare() (которая сама определена через Traits::compare()) :
- Две строки равны, если размеры
lhsиrhsравны, и каждый символ вlhsсоответствует эквивалентному символу вrhsна той же позиции. - Сравнение порядка выполняется лексикографически — сравнение выполняется функцией, эквивалентной
std::lexicographical_compareилиstd::lexicographical_compare_three_way(с C++20).
basic_string. basic_string и строку с нулевым окончанием CharT. |
Возвращаемый тип операторов трехстороннего сравнения ( Операторы |
(с C++20) |
Параметры
| lhs, rhs | - | строки, содержимое которых требуется сравнить |
Возвращаемое значение
true, если соответствующее сравнение верно, false в противном случае.static_cast</*comp-cat*/>(lhs.compare(rhs) <=> 0). Сложность
Линейная по размеру строк.
Примечания
|
Если хотя бы один параметр имеет тип |
(с C++20) |
Пример
Отчеты об ошибках
Следующие отчеты об ошибках, изменяющие поведение, были применены ретроактивно к ранее опубликованным стандартам C++.
| DR | Применено к | Поведение, как опубликовано | Корректное поведение |
|---|---|---|---|
| LWG 2064 | C++11 | совместимость использования перегрузок, принимающих две строки basic_string, была несогласованной;перегрузки, принимающие строку с нулевым окончанием CharT*, были noexcept, но могли вызывать неопределенное поведение |
согласованность достигнута; noexcept удалено |
| LWG 3432 | C++20 | возвращаемый тип operator<=> не был обязательным типом категории сравнения |
обязательный тип |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/string/basic_string/operator_cmp