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).Сложность
Линейная по размеру строк.
Примечание
|
Если хотя бы один параметр имеет тип std::string, std::wstring, std::u8string, std::u16string или std::u32string, тип возвращаемого значения |
(начиная с C++20) |
Пример
| Этот раздел не завершён Причина: нет примера |
Отчёты о дефектах
Следующие изменения поведения были применены с обратной силой к ранее опубликованным стандартам C++:
| Номер | Применён | Поведение в стандарте | Корректное поведение |
|---|---|---|---|
| LWG 2064 | C++11 | вопрос о том, являются ли перегрузки, принимающие дваbasic_string, noexcept, был противоречивым; перегрузки,принимающие CharT*, были noexcept, но могли вызватьнеопределённое поведение |
сделано последовательным; noexcept удалено |
| LWG 3432 | C++20 | тип возвращаемого значения operator<=> не обязательнодолжен быть типом категории сравнения |
требуется |