std::experimental::basic_string_view<CharT,Traits>::compare
来自 cppreference.cn
< cpp | experimental | basic string view
| constexpr int compare(basic_string_view v) const noexcept; |
(1) | (库基础 TS) |
| constexpr int compare(size_type pos1, size_type count1, basic_string_view v) const |
(2) | (库基础 TS) |
| constexpr int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const; |
(3) | (库基础 TS) |
| constexpr int compare(const CharT* s) const; |
(4) | (库基础 TS) |
| constexpr int compare(size_type pos1, size_type count1, const CharT* s) const; |
(5) | (库基础 TS) |
| constexpr int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const; |
(6) | (库基础 TS) |
比较两个字符序列。
1) 要比较序列的长度
rlen 是 size() 和 v.size() 中较小者。函数通过调用 traits::compare(data(), v.data(), rlen) 来比较两个视图,并根据下表返回一个值| 条件 | 结果 | 返回值 | |
|---|---|---|---|
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) 与比较的字符数呈线性关系。
[编辑] 另请参阅
| 按字典序比较两个视图 (函数模板) |