swap 関数 <regex>

更新 : 2007 年 11 月

2 つの 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
    要素の特徴 (traits) クラス。

解説

このテンプレート関数は、それぞれの引数の内容を交換します。処理は定数時間で実行され、例外はスローされません。

使用例

 

// std_tr1__regex__swap.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
int main() 
    { 
    std::tr1::regex rx0("c(a*)|(b)"); 
    std::tr1::regex rx1; 
    std::tr1::cmatch mr0; 
    std::tr1::cmatch mr1; 
 
    swap(rx0, rx1); 
    std::tr1::regex_search("xcaaay", mr1, rx1); 
    swap(mr0, mr1); 
 
    std::tr1::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); 
    } 
 
matched == true
length == 3
string == aaa

必要条件

ヘッダー : <regex>

名前空間 : std::tr1

参照

参照

<regex>

basic_regex クラス

match_results クラス