命名空间
变体
操作

operator==,!=,<,<=,>,>=,<=>(std::sub_match)

来自 cppreference.cn
< cpp‎ | regex‎ | sub match
 
 
 
正则表达式库
(C++11)
算法
迭代器
异常
特性
常量
(C++11)
正则表达式语法
 
std::sub_match
成员函数
非成员函数
operator==operator!=operator<<operator<=operator>operator>=operator<=>
(直到 C++20)(直到 C++20)(直到 C++20)(直到 C++20)(直到 C++20)(C++20 起)
 
定义于头文件 <regex>
直接比较
template< class BidirIt >

bool operator== ( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(1) (自 C++11 起)
template< class BidirIt >

bool operator!= ( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(2) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<  ( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(3) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<= ( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(4) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>  ( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(5) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>= ( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(6) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

auto operator<=>( const std::sub_match<BidirIt>& lhs,

                  const std::sub_match<BidirIt>& rhs );
(7) (自 C++20 起)
template< class BidirIt, class Traits, class Alloc >

bool operator== ( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(8) (自 C++11 起)
template< class BidirIt, class Traits, class Alloc >

bool operator!= ( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(9) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator<  ( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(10) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator<= ( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(11) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator>  ( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(12) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator>= ( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(13) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

auto operator<=>( const std::sub_match<BidirIt>& lhs,
                  const std::basic_string</*value-type-of*/<BidirIt>,

                                          Traits, Alloc>& str );
(14) (自 C++20 起)
template< class BidirIt, class Traits, class Alloc >

bool operator== ( const std::basic_string</*value-type-of*/<BidirIt>,
                                          Traits, Alloc>& str,

                  const std::sub_match<BidirIt>& rhs );
(15) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator!= ( const std::basic_string</*value-type-of*/<BidirIt>,
                                          Traits, Alloc>& str,

                  const std::sub_match<BidirIt>& rhs );
(16) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator<  ( const std::basic_string</*value-type-of*/<BidirIt>,
                                          Traits, Alloc>& str,

                  const std::sub_match<BidirIt>& rhs );
(17) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator<= ( const std::basic_string</*value-type-of*/<BidirIt>,
                                          Traits, Alloc>& str,

                  const std::sub_match<BidirIt>& rhs );
(18) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator>  ( const std::basic_string</*value-type-of*/<BidirIt>,
                                          Traits, Alloc>& str,

                  const std::sub_match<BidirIt>& rhs );
(19) (自 C++11 起)
(直到 C++20)
template< class BidirIt, class Traits, class Alloc >

bool operator>= ( const std::basic_string</*value-type-of*/<BidirIt>,
                                          Traits, Alloc>& str,

                  const std::sub_match<BidirIt>& rhs );
(20) (自 C++11 起)
(直到 C++20)
与 C 风格字符串比较
template< class BidirIt >

bool operator== ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(21) (自 C++11 起)
template< class BidirIt >

bool operator!= ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(22) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<  ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(23) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<= ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(24) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>  ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(25) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>= ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(26) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

auto operator<=>( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>* s );
(27) (自 C++20 起)
template< class BidirIt >

bool operator== ( const /*value-type-of*/<BidirIt>* s,

                  const std::sub_match<BidirIt>& rhs );
(28) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator!= ( const /*value-type-of*/<BidirIt>* s,

                  const std::sub_match<BidirIt>& rhs );
(29) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<  ( const /*value-type-of*/<BidirIt>* s,

                  const std::sub_match<BidirIt>& rhs );
(30) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<= ( const /*value-type-of*/<BidirIt>* s,

                  const std::sub_match<BidirIt>& rhs );
(31) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>  ( const /*value-type-of*/<BidirIt>* s,

                  const std::sub_match<BidirIt>& rhs );
(32) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>= ( const /*value-type-of*/<BidirIt>* s,

                  const std::sub_match<BidirIt>& rhs );
(33) (自 C++11 起)
(直到 C++20)
与单个字符比较
template< class BidirIt >

bool operator== ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(34) (自 C++11 起)
template< class BidirIt >

bool operator!= ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(35) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<  ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(36) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<= ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(37) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>  ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(38) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>= ( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(39) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

auto operator<=>( const std::sub_match<BidirIt>& lhs,

                  const /*value-type-of*/<BidirIt>& ch );
(40) (自 C++20 起)
template< class BidirIt >

bool operator== ( const /*value-type-of*/<BidirIt>& ch,

                  const std::sub_match<BidirIt>& rhs );
(41) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator!= ( const /*value-type-of*/<BidirIt>& ch,

                  const std::sub_match<BidirIt>& rhs );
(42) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<  ( const /*value-type-of*/<BidirIt>& ch,

                  const std::sub_match<BidirIt>& rhs );
(43) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator<= ( const /*value-type-of*/<BidirIt>& ch,

                  const std::sub_match<BidirIt>& rhs );
(44) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>  ( const /*value-type-of*/<BidirIt>& ch,

                  const std::sub_match<BidirIt>& rhs );
(45) (自 C++11 起)
(直到 C++20)
template< class BidirIt >

bool operator>= ( const /*value-type-of*/<BidirIt>& ch,

                  const std::sub_match<BidirIt>& rhs );
(46) (自 C++11 起)
(直到 C++20)
辅助类型别名
template< class BidirIt >

using /*value-type-of*/ =

    typename std::iterator_traits<BidirIt>::value_type;
(47) (仅为说明目的*)
template< class BidirIt >

using /*cat-type-of*/ =
    std::compare_three_way_result_t

        <std::basic_string</*value-type-of*/<BidirIt>>>;
(48) (自 C++20 起)
(仅为说明目的*)

sub_match 与另一个 sub_matchstd::string、C 风格字符串或单个字符进行比较。

1-7) 直接比较两个 sub_match
8-20)sub_matchstd::basic_string 进行比较。
21-33)sub_match 与 C 风格字符串进行比较。
34-46)sub_match 与单个字符进行比较。

<<=>>=!= 运算符分别从 operator<=>operator== 合成

(自 C++20 起)
47) value-type-of <BidirIt>BidirIt值类型
48) cat-type-of <BidirIt>std::sub_match<BidirIt> 的三路比较的结果类型。

目录

[edit] 参数

lhs, rhs - 要比较的 sub_match
str - 要比较的 std::basic_string
s - 要比较的 C 风格字符串的指针
ch - 要比较的字符

[edit] 返回值

target 为以下值

1-7) rhs
8-20) typename std::sub_match<BidirIt>::string_type(str.data(), str.size())
21-33) s
34-46) typename std::sub_match<BidirIt>::string_type(1, ch)

返回值定义如下

 运算符  返回值
重载 (1-14,21-27,34-40)
(带有参数 lhs 的重载)
      重载 (15-20,28-33,41-46)      
(不带参数 lhs 的重载)
== lhs.compare(target) == 0 rhs.compare(target) == 0
!= lhs.compare(target) != 0 rhs.compare(target) != 0
< lhs.compare(target) < 0 rhs.compare(target) > 0
<= lhs.compare(target) <= 0 rhs.compare(target) >= 0
> lhs.compare(target) > 0 rhs.compare(target) < 0
>= lhs.compare(target) >= 0 rhs.compare(target) <= 0
<=>  static_cast<cat-type-of <BidirIt>>
    (lhs.compare(target) <=> 0)
 
N/A

[edit] 注解

operator<=> 的返回类型保证为比较范畴类型。如果 value-type-of <BidirIt>charwchar_tchar8_tchar16_tchar32_t,则 operator<=> 的返回类型为 std::strong_ordering

[edit] 示例

[edit] 缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 应用于 已发布行为 正确行为
LWG 2217 C++11 对于与 std::string 的比较,
compare() 的实参是 str.c_str()
实参是
string_type(str.data(), str.size()))

[edit] 参见

比较已匹配的子序列(如果有)
(公开成员函数) [编辑]