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,  | 
(C++11 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
 (C++11 起)  (C++20 前)  | 
|
|   template< class CharT, class Traits, class Alloc > constexpr bool  | 
(C++20 起) | |
| (2) | ||
|   template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++11 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
 (C++11 起)  (C++20 前)  | 
|
| (3) | ||
|   template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++11 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
 (C++11 起)  (C++20 前)  | 
|
| (4) | ||
|   template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++11 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
 (C++11 起)  (C++20 前)  | 
|
| (5) | ||
|   template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++11 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
 (C++11 起)  (C++20 前)  | 
|
| (6) | ||
|   template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++11 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
 (C++11 起)  (C++20 前)  | 
|
|   template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/  | 
(7) | (C++20 起) | 
|   比较一个  basic_string 与 T 的空终止数组 | 
||
| (8) | ||
|   template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > constexpr bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 起) | |
|   template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs,  | 
(C++20 前) | |
| (9) | ||
|   template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs,  | 
(C++20 前) | |
| (10) | ||
|   template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs,  | 
(C++20 前) | |
| (11) | ||
|   template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs,  | 
(C++20 前) | |
| (12) | ||
|   template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs,  | 
(C++20 前) | |
| (13) | ||
|   template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs,  | 
(C++20 前) | |
|   template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/  | 
(14) | (C++20 起) | 
比较 string 与另一 string 或 CharT 的空终止数组的内容。
所有比较通过 compare() 成员函数进行(它自身以 Traits::compare() 定义):
-  若 
lhs与rhs的大小相等,且lhs中的每个字符有在rhs中在同一位置的等价字符,则二个字符串相等。 
- 顺序比较按字典序——以等价于 std::lexicographical_compare 或 std::lexicographical_compare_three_way (C++20 起)的函数进行比较。
 
basic_string 对象。basic_string 对象和 CharT 的空终止数组。| 
 三路比较运算符的返回类型( /*comp-cat*/ )为 Traits::comparison_category ,若该有限定标识合法并指代类型,否则为 std::weak_ordering 。若 /*comp-cat*/ 不是比较类别类型,则程序非良构。 
  | 
(C++20 起) | 
参数
| lhs, rhs | - | 要比较内容的字符串 | 
返回值
复杂度
与字符串大小成线性。
注解
| 
 若至少一个参数拥有类型 std::string 、 std::wstring 、 std::u8string 、 std::u16string 或 std::u32string ,则   | 
(C++20 起) | 
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 | 
|---|---|---|---|
| LWG 2064 | C++11 |  接收二个 basic_string 的重载是否为 noexcept 不一致;接收一个 CharT* 的重载为 noexcept 但可能引发 UB
 | 
 使之一致; 移除 noexcept  | 
| LWG 3432 | C++20 |  未要求 operator<=> 的返回类型为比较类别类型
 | 
已要求 |