Namespaces
Variants

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

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
std::sub_match
Member functions
Non-member functions
operator== operator!= operator<< operator<= operator> operator>= operator<=>
(until C++20) (until C++20) (until C++20) (until C++20) (until 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 起)
(

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

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

< <= > >= != 运算符分别由 operator <=> operator == 自动合成。

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

目录

参数

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

返回值

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 )
不适用

备注

operator <=> 的返回类型保证是比较类别类型。若 value-type-of  < BidirIt > char wchar_t char8_t char16_t char32_t ,则 operator<=> 的返回类型为 std::strong_ordering

示例

缺陷报告

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

缺陷报告 适用范围 发布时行为 正确行为
LWG 2217 C++11 std::string 进行比较时,
compare() 的参数为 str. c_str ( )
参数应为
string_type ( str. data ( ) , str. size ( ) ) )

参见

比较匹配的子序列(如果存在)
(公开成员函数)