函式模板
<regex>

std::operators (match_results)

相等 (1)
template <class BidirectionalIterator, class Alloc>  bool operator== ( const match_results<BidirectionalIterator,Alloc>& lhs,                    const match_results<BidirectionalIterator,Alloc>& rhs );
不等 (2)
template <class BidirectionalIterator, class Alloc>  bool operator!= ( const match_results<BidirectionalIterator,Alloc>& lhs,                    const match_results<BidirectionalIterator,Alloc>& rhs );
match_results 的關係運算符
返回 match_results 物件 lhsrhs 之間適當的相等或不等比較運算的結果。

相等比較的過程如下(如果在過程中找到確定的答案,則停止):
  • 如果兩個物件都未就緒,則為 true。
  • 如果只有一個物件就緒,則為 false。
  • 如果兩個物件都為空,則為 true。
  • 如果兩個字首比較不相等,則為 false。
  • 如果兩個大小不同,則為 false。
  • 如果演算法 equal 在比較兩個物件中的 sub_match 元素範圍時返回 false,則為 false。
  • 如果兩個字尾相等,則為 true。
  • 否則,為 false。
對於不等比較,結果是相反的。

引數

lhs, rhs
match_results 容器(分別位於運算子的左側和右側),兩者都具有相同的模板引數(BidirectionalIteratorAlloc).

返回值

true如果條件成立,則為 true,並且false否則為 false。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// match_results comparisons
// - using cmatch, a standard alias of match_results<const char*>
#include <iostream>
#include <regex>

int main ()
{
  std::cmatch m1,m2,m3;

  std::regex_search ( "a needle in the haystack", m1, std::regex("needle") );
  std::regex_search ( "a needle in the haystack", m2, std::regex("needle") );
  std::regex_search ( "the needle in a haystack", m3, std::regex("needle") );

  if (m1==m2) std::cout << "m1 and m2 are equal\n";
  if (m2!=m3) std::cout << "m2 and m3 are not equal\n";  // prefix() don't match

  return 0;
}

輸出
a and b are equal
b and c are not equal


另見