operator==,!=,<,<=,>,>=,<=> (std::basic_string)
|
ヘッダーで定義
<string>
|
||
|
二つの
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) | (constexpr since C++20) |
|
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以降) |
文字列の内容を別の文字列またはnull終端配列と比較します。
CharT
。
すべての比較は
compare()
メンバ関数(これはそれ自体が
Traits::compare()
で定義されています)を通じて行われます:
- 2つの文字列は、 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 | - | 内容を比較する文字列 |
戻り値
計算量
文字列のサイズに対して線形。
注記
|
少なくとも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だが未定義動作を引き起こす可能性があった
|
一貫性を持たせた;
noexceptを削除 |
| LWG 3432 | C++20 |
operator<=>
の戻り値型が比較カテゴリ型であることが要求されていなかった
|
要求するように変更 |