function template
<regex>
std::operators (match_results)
equality (1) |
template <class BidirectionalIterator, class Alloc>
bool operator== ( const match_results<BidirectionalIterator,Alloc>& lhs,
const match_results<BidirectionalIterator,Alloc>& rhs );
|
---|
inequality (2) |
template <class BidirectionalIterator, class Alloc>
bool operator!= ( const match_results<BidirectionalIterator,Alloc>& lhs,
const match_results<BidirectionalIterator,Alloc>& rhs ); |
---|
Relational operators for match_results
Returns the result of the appropriate equality or inequality comparison operation between the match_results objects lhs and rhs.
The procedure for the equality comparison is as follows (stopping at any point if the procedure finds a conclusive answer):
- If neither object is ready, true.
- If only one object is ready, false.
- If both objects are empty, true.
- If both prefixes do not compare equal, false.
- If both sizes are different, false.
- If the algorithm equal would return false for comparing the ranges of sub_match elements in both objects, false.
- If both suffixes are equal, true.
- Otherwise, false.
For the inequality comparison, the result is the opposed one.
Parameters
- lhs, rhs
- match_results containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (BidirectionalIterator and Alloc).
Return Value
true if the condition holds, and false otherwise.
Example
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;
}
|
Output:
a and b are equal
b and c are not equal
|