operator==,!=(std::match_results)

来自cppreference.com
< cpp‎ | regex‎ | match results


在标头 <regex> 定义
template< class BidirIt, class Alloc >

bool operator==( match_results<BidirIt,Alloc>& lhs,

                 match_results<BidirIt,Alloc>& rhs );
(1) (C++11 起)
template< class BidirIt, class Alloc >

bool operator!=( match_results<BidirIt,Alloc>& lhs,

                 match_results<BidirIt,Alloc>& rhs );
(2) (C++11 起)
(C++20 前)

比较两个 match_results 对象。

若满足下列条件则两个 match_results 相等:

  • 无一对象为就绪,或
  • 两个匹配结果均为就绪且满足下列条件:
  • lhs.empty() 且 rhs.empty() ,或
  • !lhs.empty() 且 !rhs.empty() 并满足下列条件:
  • lhs.prefix() == rhs.prefix()
  • lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin())
  • lhs.suffix() == rhs.suffix()
1) 检查 lhs 与 rhs 是否相等。
2) 检查 lhs 与 rhs 是否不相等。

!= 运算符从 operator== 运算符合成。

(C++20 起)

参数

lhs, rhs - 要比较的匹配结果
类型要求
-
BidirIt 必须满足老式双向迭代器 (LegacyBidirectionalIterator) 。
-
Alloc 必须满足分配器 (Allocator) 。

返回值

1) 若 lhs 与 rhs 相等则为 true,否则为 false。
2) 若 lhs 与 rhs 不相等则为 true,否则为 false。

异常

可能会抛出由实现定义的异常。

示例