operator==,!=,<,<=,>,>=,<=>(std::basic_string)
| ヘッダ <string> で定義 |
||
| 2つの basic_stringオブジェクトを比較します |
||
| template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(1) | (C++11 以降 noexcept) (C++20 以降 constexpr) |
| template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(2) | (C++20まで) (C++11 以降 noexcept) |
| template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(3) | (C++20まで) (C++11 以降 noexcept) |
| template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(4) | (C++20まで) (C++11 以降 noexcept) |
| template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(5) | (C++20まで) (C++11 以降 noexcept) |
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(6) | (C++20まで) (C++11 以降 noexcept) |
| template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ |
(7) | (C++20以降) |
basic_stringオブジェクトとヌル終端T配列を比較します |
||
| template< class CharT, class Traits, class Alloc > bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(8) | (C++20 以降 constexpr) |
| template< class CharT, class Traits, class Alloc > bool operator==( const CharT* lhs, |
(9) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(10) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator!=( const CharT* lhs, |
(11) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(12) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator<( const CharT* lhs, |
(13) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(14) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator<=( const CharT* lhs, |
(15) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(16) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator>( const CharT* lhs, |
(17) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs, |
(18) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > bool operator>=( const CharT* lhs, |
(19) | (C++20まで) |
| template< class CharT, class Traits, class Alloc > constexpr /*comp-cat*/ |
(20) | (C++20以降) |
文字列の内容を別の文字列またはヌル終端CharT配列と比較します。
すべての比較はcompare()メンバー関数を介して行われます(これはTraits::compare()で定義されています)。
- 2つの文字列が等しいとは、lhsとrhsのサイズが等しく、lhsの各文字がrhsの同じ位置にある同等の文字を持っている場合です。
- 順序比較は辞書順に行われます。比較はstd::lexicographical_compareまたはstd::lexicographical_compare_three_wayに相当する関数によって実行されます。
basic_stringオブジェクトを比較します。basic_stringオブジェクトとヌル終端CharT配列を比較します。|
3方向比較演算子(/*comp-cat*/)の戻り値の型は、その修飾IDが存在し、型を指す場合はTraits::comparison_category、それ以外の場合はstd::weak_orderingです。/*comp-cat*/が比較カテゴリ型でない場合、プログラムは不正形式になります。
|
(C++20以降) |
目次 |
[編集] パラメータ
| lhs, rhs | - | 比較する文字列 |
[編集] 戻り値
[編集] 計算量
文字列のサイズに対して線形。
[編集] 注記
|
少なくとも1つのパラメータがstd::string、std::wstring、std::u8string、std::u16string、またはstd::u32stringの型である場合、 |
(C++20以降) |
[編集] 例
| このセクションは未完成です 理由: 例がありません |
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2064 | C++11 | 2つのbasic_stringを取るオーバーロードがnoexceptであったかどうかは一貫性がありませんでした。CharT*を取るオーバーロードはnoexceptでしたが、UBを引き起こす可能性がありました。 |
一貫性を持たせました。 noexcept 削除 |
| LWG 3432 | C++20 | operator<=>の戻り値の型は、比較カテゴリ型である必要はありませんでした。 |
必要 |