std::match_results::ready

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

版本历史

  • (当前 | 先前 2017年9月28日 (四) 21:19Fruderica讨论 | 贡献. . (1,109字节) (-122). . (撤销)
  • 当前 | 先前 2012年11月2日 (五) 12:08P12bot讨论 | 贡献 . . (1,231字节) (+297). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 09:07P12讨论 | 贡献 . . (934字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (934字节) (-16). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 15:33P12讨论 | 贡献 . . (950字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (950字节) (+950). . (Translated from the English version using Google Translate)