std::basic_string_view<CharT,Traits>::compare
提供: cppreference.com
< cpp | string | basic string view
constexpr int compare(basic_string_view v) const noexcept; |
(1) | (C++17以上) |
constexpr int compare(size_type pos1, size_type count1, basic_string_view v) const; |
(2) | (C++17以上) |
constexpr int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const; |
(3) | (C++17以上) |
constexpr int compare(const CharT* s) const; |
(4) | (C++17以上) |
constexpr int compare(size_type pos1, size_type count1, const CharT* s) const; |
(5) | (C++17以上) |
constexpr int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const; |
(6) | (C++17以上) |
2つの文字シーケンスを比較します。
1) 比較するシーケンスの長さ
rlen
は size() と v.size() の小さい方です。 この関数は traits::compare(data(), v.data(), rlen) を呼ぶことによって2つのビューを比較し、以下の表に従って値を返します。条件 | 結果 | 戻り値 | |
---|---|---|---|
Traits::compare(data(), v.data(), rlen) < 0
|
this が v より小さい
|
<0 | |
Traits::compare(data(), v.data(), rlen) == 0
|
size() < v.size()
|
this が v より小さい
|
<0 |
size() == v.size()
|
this が v と等しい
|
0 | |
size() > v.size()
|
this が v より大きい
|
>0 | |
Traits::compare(data(), v.data(), rlen) > 0
|
this が v より大きい
|
>0 |
2) substr(pos1, count1).compare(v) と同等です。
3) substr(pos1, count1).compare(v.substr(pos2, count2)) と同等です。
4) compare(basic_string_view(s)) と同等です。
5) substr(pos1, count1).compare(basic_string_view(s)) と同等です。
6) substr(pos1, count1).compare(basic_string_view(s, count2)) と同等です。
目次 |
[編集] 引数
v | - | 比較するビュー |
s | - | 比較する文字列を指すポインタ |
count1 | - | 比較するこのビューの文字数 |
pos1 | - | 比較するこのビューの最初の文字の位置 |
count2 | - | 比較する指定されたビューの文字数 |
pos2 | - | 比較する指定されたビューの最初の文字の位置 |
[編集] 戻り値
このビューが他方の文字シーケンスより小さければ負の値、両方の文字シーケンスが等しければゼロ、このビューが他方の文字シーケンスより大きければ正の値。
[編集] 計算量
1) 比較する文字数に比例。
[編集] 関連項目
(C++20で削除)(C++20で削除)(C++20で削除)(C++20で削除)(C++20で削除)(C++20) |
2つの文字列ビューを辞書的に比較します (関数テンプレート) |