swap Function <regex>
交換兩個 basic_regex 或 match_results 物件。
template<class Elem, class RXtraits>
void swap(basic_regex<Elem, RXtraits, Alloc>& left,
basic_regex<Elem, RXtraits>& right) throw();
template<class Elem, class IOtraits, class BidIt, class Alloc>
void swap(match_results<BidIt, Alloc>& left,
match_results<BidIt, Alloc>& right) throw();
參數
Elem
項目的型別來對應。RXtraits
項目特性類別。
備註
樣板函式交換它們在常數時間的個別引數的內容,且不會擲回例外狀況。
範例
// std_tr1__regex__swap.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
std::regex rx0("c(a*)|(b)");
std::regex rx1;
std::cmatch mr0;
std::cmatch mr1;
swap(rx0, rx1);
std::regex_search("xcaaay", mr1, rx1);
swap(mr0, mr1);
std::csub_match sub = mr0[1];
std::cout << "matched == " << std::boolalpha
<< sub.matched << std::endl;
std::cout << "length == " << sub.length() << std::endl;
std::cout << "string == " << sub << std::endl;
return (0);
}
需求
標題: <regex>
命名空間: std