public member function
<regex>

std::match_results::ready

bool ready() const;
Test whether results are ready
Returns true if the match_results object has a fully established result state, and false otherwise.

When the object is default-constructed, this value is initialized to false. Any call to regex_match or regex_search with the match_results object as argument sets this value to true, even if the function does not succeed in finding any match.

To check whether there were matches after a particular call to regex_match or regex_search, you can use match_results::empty.

When the object is obtained by dereferencing a valid regex_iterator, this value is always true.

Parameters

none

Return value

true if the object has a fully established result state. false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// match_results::ready
// - using smatch, a standard alias of match_results<string::iterator>
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string mystring ("subject");
  std::smatch mymatch;
  std::regex myregex ("sub.*");

  std::cout << std::boolalpha;
  std::cout << "mymatch.ready() is " << mymatch.ready() << std::endl;

  std::regex_match ( mystring, mymatch, myregex );
  std::cout << "attempting match..." << std::endl;
  
  std::cout << "mymatch.ready() is " << mymatch.ready() << std::endl;

  if (mymatch.ready()) std::cout << "matched: " << mymatch[0] << std::endl;

  return 0;
}

Output:
mymatch.ready() is false
attempting match...
mymatch.ready() is true
matched: subject


See also