Namespaces
Variants

std::sub_match<BidirIt>:: swap

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
void swap ( sub_match & s ) noexcept ( /* ver más abajo */ ) ;
(desde C++11)

Intercambia los contenidos de dos objetos de subcoincidencia. Equivalente a

this - > pair < BidirIt, BidirIt > :: swap ( s ) ;
std:: swap ( matched, s. matched ) ;

Contenidos

Parámetros

s - un sub_match para intercambiar con
Requisitos de tipo
-
BidirIt debe cumplir con los requisitos de LegacySwappable .

Excepciones

noexcept especificación:
noexcept ( std:: is_nothrow_swappable_v < BidirIt > )

Ejemplo

#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);
}

Salida:

Before swap:
x.str() = []
y.str() = [cat]
After swap:
x.str() = [cat]
y.str() = []

Informes de defectos

Los siguientes informes de defectos que modifican el comportamiento se aplicaron retroactivamente a los estándares de C++ publicados anteriormente.

DR Aplicado a Comportamiento publicado Comportamiento correcto
LWG 3204 C++11 std::sub_match utilizaba el heredado std :: pair :: swap ( pair & )
lo que provocaba un slicing
std :: sub_match :: swap ( sub_match & ) se añade