Namespaces
Variants

std::experimental::basic_string_view<CharT,Traits>:: compare

From cppreference.net
constexpr int compare ( basic_string_view v ) const noexcept ;
(1) (库基础技术规范)
constexpr int compare ( size_type pos1, size_type count1,
basic_string_view v ) const
(2) (库基础技术规范)
constexpr int compare ( size_type pos1, size_type count1, basic_string_view v,
size_type pos2, size_type count2 ) const ;
(3) (库基础技术规范)
constexpr int compare ( const CharT * s ) const ;
(4) (库基础技术规范)
constexpr int compare ( size_type pos1, size_type count1,
const CharT * s ) const ;
(5) (库基础技术规范)
constexpr int compare ( size_type pos1, size_type count1,
const CharT * s, size_type count2 ) const ;
(6) (库基础技术规范)

比较两个字符序列。

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) 与比较的字符数量呈线性关系。

参见

按字典序比较两个视图
(函数模板)