名前空間
変種
操作

operator==,!=,<,<=,>,>=,<=>(std::basic_string)

提供: cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
非メンバ関数
入出力
比較
operator==operator!=operator<operator>operator<=operator>=operator<=>
(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20)
数値変換 (C++11)
ヘルパークラス
推定ガイド(C++17)
 
ヘッダ <string> で定義
2つの basic_string オブジェクトの比較
(1)
template<class CharT, class Traits, class Alloc >

bool operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++14未満)
template<class CharT, class Traits, class Alloc >

bool operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++14以上)
(C++20未満)
template<class CharT, class Traits, class Alloc >

constexprbool
    operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++20以上)
(2)
template<class CharT, class Traits, class Alloc >

bool operator!=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++14未満)
template<class CharT, class Traits, class Alloc >

bool operator!=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++14以上)
(C++20未満)
(3)
template<class CharT, class Traits, class Alloc >

bool operator<(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++14未満)
template<class CharT, class Traits, class Alloc >

bool operator<(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++14以上)
(C++20未満)
(4)
template<class CharT, class Traits, class Alloc >

bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++14未満)
template<class CharT, class Traits, class Alloc >

bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++14以上)
(C++20未満)
(5)
template<class CharT, class Traits, class Alloc >

bool operator>(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++14未満)
template<class CharT, class Traits, class Alloc >

bool operator>(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++14以上)
(C++20未満)
(6)
template<class CharT, class Traits, class Alloc >

bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++14未満)
template<class CharT, class Traits, class Alloc >

bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(C++14以上)
(C++20未満)
template<class CharT, class Traits, class Alloc >

constexpr/*comp-cat*/
    operator<=>(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs )noexcept;
(7) (C++20以上)
basic_string オブジェクトと T のNULL終端配列の比較
(8)
template<class CharT, class Traits, class Alloc >

bool operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 const CharT* rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

constexprbool operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                           const CharT* rhs );
(C++20以上)
template<class CharT, class Traits, class Alloc >

bool operator==(const CharT* lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++20未満)
(9)
template<class CharT, class Traits, class Alloc >

bool operator!=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 const CharT* rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

bool operator!=(const CharT* lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++20未満)
(10)
template<class CharT, class Traits, class Alloc >

bool operator<(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                const CharT* rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

bool operator<(const CharT* lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++20未満)
(11)
template<class CharT, class Traits, class Alloc >

bool operator<=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 const CharT* rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

bool operator<=(const CharT* lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++20未満)
(12)
template<class CharT, class Traits, class Alloc >

bool operator>(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                const CharT* rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

bool operator>(const CharT* lhs,

                conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++20未満)
(13)
template<class CharT, class Traits, class Alloc >

bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 const CharT* rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

bool operator>=(const CharT* lhs,

                 conststd::basic_string<CharT,Traits,Alloc>& rhs );
(C++20未満)
template<class CharT, class Traits, class Alloc >

constexpr/*comp-cat*/
    operator<=>(conststd::basic_string<CharT,Traits,Alloc>& lhs,

                 const CharT* rhs );
(14) (C++20以上)

文字列の内容を別の文字列または CharT のヌル終端配列と比較します。

すべての比較は compare() メンバ関数を通して行われます (compare() 自身は Traits::compare() によって定義されます)。

  • lhsrhs のサイズが等しく、 lhs 内のそれぞれの文字が rhs 内の同じ位置の文字と等しければ、2つの文字列は等しくなります。
  • 順序比較は辞書的に行われます。 比較は std::lexicographical_compare または std::lexicographical_compare_three_way(C++20以上) と同等な関数によって行われます。

三方比較演算子の戻り値の型 (/*comp-cat*/) は、存在すれば Traits::comparison_category、そうでなければ std::weak_ordering です。

(C++20以上)
1-7) 2つの basic_string オブジェクトを比較します。
8-14)basic_string オブジェクトと CharT のヌル終端配列を比較します。

目次

[編集]引数

lhs, rhs - 内容を比較する文字列

[編集]戻り値

1-6,8-13) 対応する比較が成立すれば true、そうでなければ false
7,14)static_cast</*comp-cat*/>(lhs.compare(rhs)<=>0)

[編集]計算量

文字列のサイズに比例。

[編集]ノート

少なくとも1つの引数の型が std::stringstd::wstringstd::u8stringstd::u16string または std::u32string である場合、 operator<=> の戻り値の型は std::strong_ordering です。

(C++20以上)
close