std::experimental::basic_string_view<CharT,Traits>::compare
From cppreference.com
< cpp | experimental | basic string view
| constexpr int compare(basic_string_view v) const noexcept; |
(1) | (Library Fundamentals TS) |
| constexpr int compare(size_type pos1, size_type count1, basic_string_view v) const |
(2) | (Library Fundamentals TS) |
| constexpr int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const; |
(3) | (Library Fundamentals TS) |
| constexpr int compare(const CharT* s) const; |
(4) | (Library Fundamentals TS) |
| constexpr int compare(size_type pos1, size_type count1, const CharT* s) const; |
(5) | (Library Fundamentals TS) |
| constexpr int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const; |
(6) | (Library Fundamentals TS) |
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 | - | 比較対象の C 文字列へのポインタ |
| count1 | - | このビューで比較する文字数 |
| pos1 | - | このビューで比較する最初の文字の位置 |
| count2 | - | 指定されたビューで比較する文字数 |
| pos2 | - | 指定されたビューの最初の文字の位置 |
[編集] 戻り値
このビューが他の文字シーケンスより小さい場合は負の値、両方の文字シーケンスが等しい場合はゼロ、このビューが他の文字シーケンスより大きい場合は正の値を返します。
[編集] 計算量
1) 比較される文字数に対して線形。
[編集] 関連項目
| 2つのビューを辞書順に比較します (function template) |