std::match_results<BidirIt,Alloc>::ready

来自cppreference.com
< cpp‎ | regex‎ | match results
bool ready() const;
(C++11 起)

指示 match_results 是否就绪(合法)。

默认构造的 match_results 无结果状态(未就绪),而且只能由正则表达式算法之一变为就绪。就绪状态隐含已经完整建立了所有匹配结果。

在未就绪的 match_results 对象上调用大多数成员函数的结果未定义。

返回值

若 match_results 就绪则为 true ,否则为 false

示例

#include <iostream>
#include <regex>
#include <string>
 
int main()
{
    std::string target("pattern");
    std::smatch sm;
    std::cout << "default constructed smatch is "
              << (sm.ready() ? " ready\n" : " not ready\n");
 
    std::regex re1("tte");
    std::regex_search(target, sm, re1);
 
    std::cout << "after search, smatch is "
              << (sm.ready() ? " ready\n" : " not ready\n");
}

输出:

default constructed smatch is  not ready
after search, smatch is  ready