Namespaces
Variants

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

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
bool ready ( ) const ;
(自 C++11 起)

指示匹配结果是否已就绪(有效)。

默认构造的匹配结果不具备结果状态(不处于 就绪 状态),只能通过正则表达式算法使其就绪。 就绪 状态意味着所有匹配结果已完全建立。

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

返回值

true 表示匹配结果已就绪, false 表示未就绪。

示例

#include <iostream>
#include <regex>
#include <string>
int main()
{
    std::string target("big-red-cat");
    std::smatch sm;
    std::cout << "Default constructed smatch is "
              << (sm.ready() ? "ready.\n" : "not ready.\n");
    std::regex re1(".*-red-.*");
    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.