std::sub_match<BidirIt>::swap
void swap( sub_match& s ) noexcept(/* see below */); | (начиная с C++11) |
Обменивает содержимое двух объектов подсовпадения. Эквивалентно
this->pair<BidirIt, BidirIt>::swap(s);std::swap(matched, s.matched);
Параметры
| s | - | объект sub_match для обмена с ним |
| Требования к типам | ||
-BidirIt должен удовлетворять требованиям LegacySwappable. |
||
Исключения
Спецификация
noexcept: noexcept(std::is_nothrow_swappable_v<BidirIt>)
Пример
#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);
}
Вывод:
Before swap: x.str() = [] y.str() = [cat] After swap: x.str() = [cat] y.str() = []
Отчёты об ошибках
Следующие отчёты об ошибках, изменяющие поведение, были применены задним числом к ранее опубликованным стандартам C++.
| DR | Применяется к | Поведение в опубликованной версии | Правильное поведение |
|---|---|---|---|
| LWG 3204 | C++11 |
std::sub_match использовал унаследованный std::pair::swap(pair&)что приводило к срезке |
Добавлен std::sub_match::swap(sub_match&) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/regex/sub_match/swap