- regex[meta header]
- std[meta namespace]
- match_results[meta class]
- function[meta id-type]
- cpp11[meta cpp]
bool ready() const;
マッチ結果が利用可能か否かを返す。
マッチ結果が利用可能である場合 true
、利用可能ではない場合 false
regex_match
、および、regex_search
の引数に渡したmatch_results
オブジェクトは、マッチが成功しなくてもready() == true
となる。
match_results
オブジェクトでマッチが成功したか否かを確認する場合には、regex_match
、および、regex_search
の戻り値を使用するか、empty
を使用すると良い。regex_iterator
を間接参照して得られるmatch_results
オブジェクトは、必ずready() == true
となる。ready() != true
の場合、match_results
のほとんどのメンバ関数は使用できないため、注意が必要である(各メンバ関数の「要件」を参照)。
#include <iostream>
#include <regex>
int main()
{
const char s1[] = " abc ";
const char s2[] = " 012 ";
const std::regex re("\\d+");
std::cmatch m;
// regex_search 実行前
std::cout << std::boolalpha << "ready = " << m.ready() << ", empty = " << m.empty() << std::endl;
// regex_search 実行後(マッチ失敗)
if (std::regex_search(s1, m, re)) {
std::cout << "match:ready = " << m.ready() << ", empty = " << m.empty() << std::endl;
} else {
std::cout << "not match:ready = " << m.ready() << ", empty = " << m.empty() << std::endl;
}
// regex_search 実行後(マッチ成功)
if (std::regex_search(s2, m, re)) {
std::cout << "match:ready = " << m.ready() << ", empty = " << m.empty() << std::endl;
} else {
std::cout << "not match:ready = " << m.ready() << ", empty = " << m.empty() << std::endl;
}
}
- std::regex[link ../basic_regex.md]
- std::cmatch[link ../match_results.md]
- std::regex_search[link ../regex_search.md]
- m.ready()[color ff0000]
- m.empty()[link empty.md]
ready = false, empty = true
not match:ready = true, empty = true
match:ready = true, empty = false
- C++11
- Clang: 3.0 [mark verified], 3.1 [mark verified], 3.2 [mark verified], 3.3 [mark verified], 3.4 [mark verified], 3.5 [mark verified], 3.6 [mark verified]
- GCC: 4.9.0 [mark verified], 4.9.1 [mark verified], 5.0.0 [mark verified]
- ICC: ??
- Visual C++: ??