std::sub_match<BidirIt>::swap
From cppreference.com
| void swap( sub_match& s ) noexcept(/* 以下参照 */); |
(C++11以降) | |
2つのサブマッチオブジェクトの内容を交換します。以下と同等です。
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&) が追加されました。 |