| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Classes | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Algorithms | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Iterators | ||||
(C++11) | ||||
(C++11) | ||||
| Exceptions | ||||
(C++11) | ||||
| Traits | ||||
(C++11) | ||||
| Constants | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Regex Grammar | ||||
(C++11) |
| Member functions | ||||
sub_match::swap | ||||
| Non-member functions | ||||
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20) | ||||
void swap( sub_match& s)noexcept(/* see below */); | (since C++11) | |
Exchanges the contents of two sub-match objects. Equivalent to
this->pair<BidirIt, BidirIt>::swap(s);
std::swap(matched, s.matched);
Contents |
| s | - | asub_match to swap with |
| Type requirements | ||
-BidirIt must meet the requirements ofLegacySwappable. | ||
#include <cassert>#include <iostream>#include <regex> int main(){constchar* s="Quick red cat";std::sub_match<constchar*> 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);}
Output:
Before swap:x.str() = []y.str() = [cat]After swap:x.str() = [cat]y.str() = []
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3204 | C++11 | std::sub_match used inheritedstd::pair::swap(pair&) which led to a slicing | std::sub_match::swap(sub_match&) is added |