std::sub_match<BidirIt>::swap

Exchanges the contents of two sub-match objects. Equivalent to

# Declarations

void swap( sub_match& s ) noexcept(/* see below */);

(since C++11)

# Parameters

# Example

#include <cassert>
#include <iostream>
#include <regex>
 
int main()
{
    const char* s = "Quick red cat";
    std::sub_match<const char*> x, y;
 
    x.first = &s[0];
    x.second = &s[5];
    x.matched = false;
 
    y.first = &s[012];
    y.second = &s[13];
    y.matched = true;
 
    std::cout << "Before swap:\n";
    std::cout << "x.str() = [" << x.str() << "]\n";
    std::cout << "y.str() = [" << y.str() << "]\n";
    assert(!x.matched and y.matched);
 
    x.swap(y);
 
    std::cout << "After swap:\n";
    std::cout << "x.str() = [" << x.str() << "]\n";
    std::cout << "y.str() = [" << y.str() << "]\n";
    assert(x.matched and !y.matched);
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3204C++11std::sub_match used inherited std::pair::swap(pair&)which led to a slicingstd::sub_match::swap(sub_match&) is added