std::match_results::ready(3)
β¨ NAME β¨
std::match_results::ready β the one that tells you if your match results are actually, you know, ready π
okay so real quick β this page lives in the C++ Standard Libary manual, and yes bestie we're talking about std::match_results::ready today π
πΈ Synopsis πΈ
bool ready() const; (since C++11)
It literally just tells you whether the match results are ready (valid) or not π¦
A default-constructed match result has no result state (so it is not ready), and the only way to make it ready is by handing it to one of the regex algorithms. Being in the ready state means all the match results have been fully established β like, fully cooked, no notes π₯
β οΈ and here's the part where you pay attention, bestie: if you call most of the member functions on a match_results object that is not ready, the result is undefined. Undefined!! Not "returns garbage", not "throws", undefined. So don't do that π
π Return value π
trueβ the match results are ready β¨falseβ they are not π
π Example π
Run this code, it's giving tutorial but make it cute:
#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");
}
β Output β
default constructed smatch is not ready
after search, smatch is ready
see?? the default-constructed one is not ready, then std::regex_search does its little main character thing and boom β ready π
β¨
π«Ά that's the whole page, no cap. none of the facts got skipped, we just made them slay.
π source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::match_results::ready(3) β mwah, thanks for reading bestie, go forth and check your .ready() before you touch anything else ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms