std::sub_match<BidirIt>:: swap
|
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
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é |