template <class BidirectionalIterator, class Alloc>
void swap ( match_results<BidirectionalIterator,Alloc>& lhs,
Swap contents of two match_result objects
The contents of lhs are exchanged with those of rhs. Both container objects must be of the same type (same template parameters), although sizes may differ.
After the call to this member function, the matches in lhs are those which were in rhs before the call, and the matches of rhs are those which were in lhs.
This is a specialization of the generic algorithm swap that improves its performance by exchanging internal pointers to data, without actually performing any copies or moves on the individual elements.
- match_results containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (BidirectionalIterator and Alloc).
// swap match_results
// - using smatch, a standard alias of match_results<string::iterator>
int main ()
std::string s ("There is a needle in this haystack.");
std::regex_search ( s, m1, std::regex("needle") );
std::regex_search ( s, m2, std::regex("haystack") );
std::cout << m1.format("m1 contains [$0].") << std::endl;
std::cout << m2.format("m2 contains [$0].") << std::endl;
m1 contains [haystack].
m2 contains [needle].
- Swap contents (public member function)
- Exchange values of two objects (function template
- Exchange values of two ranges (function template