operator== <regex>
各種オブジェクトの等価性 (等しい) を比較します。
template<class BidIt>
bool operator==(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
bool operator==(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
bool operator==(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template<class BidIt>
bool operator==(const typename iterator_traits<BidIt>::value_type* left,
const sub_match<BidIt>& right);
template<class BidIt>
bool operator==(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type* right);
template<class BidIt>
bool operator==(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template<class BidIt>
bool operator==(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
template<class BidIt, class Alloc>
bool operator==(const match_results<BidIt, Alloc>& left,
const match_results<BidIt, Alloc>& right);
パラメーター
BidIt
反復子の型。IOtraits
文字列の特徴 (traits) クラス。Alloc
アロケーター クラス。left
比較の左辺のオブジェクト。right
比較の右辺のオブジェクト。
解説
それぞれのテンプレート演算子は、各引数を文字列型に変換し、変換後のオブジェクトの等価性を比較して、その結果を返します。
テンプレート演算子によって引数が文字列型に変換されるとき、次の順序で最初に該当する変換方法が使用されます。
引数の型がテンプレート クラス match_results または sub_match から特化したクラスである場合は、str メンバー関数を呼び出すことによって変換されます。
引数の型がテンプレート クラス basic_string から特化したクラスである場合、型変換は実行されません。
それ以外の引数の型は、引数の値をテンプレート クラス basic_string から特化したクラスの適切なコンストラクターに渡すことによって変換されます。
使用例
// std_tr1__regex__operator_eq.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "match == " << mr.str() << std::endl;
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "match == match == " << std::boolalpha
<< (mr == mr) << std::endl;
std::cout << "sub == sub == " << std::boolalpha
<< (sub == sub) << std::endl;
std::cout << "string(\"aab\") == sub == " << std::boolalpha
<< (Mystr("aab") == sub) << std::endl;
std::cout << "sub == string(\"aab\") == " << std::boolalpha
<< (sub == Mystr("aab")) << std::endl;
std::cout << "\"aab\" == sub == " << std::boolalpha
<< ("aab" == sub) << std::endl;
std::cout << "sub == \"aab\" == " << std::boolalpha
<< (sub == "aab") << std::endl;
std::cout << "'a' == sub == " << std::boolalpha
<< ('a' == sub) << std::endl;
std::cout << "sub == 'a' == " << std::boolalpha
<< (sub == 'a') << std::endl;
return (0);
}
必要条件
ヘッダー : <regex>
名前空間: std