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 ( /* voir ci-dessous */ ) ;
(depuis C++11)

Échange le contenu de deux sous-correspondances. Équivalent à

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

Table des matières

Paramètres

s - un sub_match à échanger
Exigences de type
-
BidirIt doit satisfaire aux exigences de LegacySwappable .

Exceptions

noexcept spécification :
noexcept ( std:: is_nothrow_swappable_v < BidirIt > )

Exemple

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

Sortie :

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

Rapports de défauts

Les rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.

DR Appliqué à Comportement publié Comportement corrigé
LWG 3204 C++11 std::sub_match utilisait l'héritage std :: pair :: swap ( pair & )
ce qui provoquait un slicing
std :: sub_match :: swap ( sub_match & ) est ajouté