std::match_results::size(3)
okay bestie, welcome to std::match_results::size(3) from the C++ Standard Libary β yes, thatβs the manual name, typo and all π«Ά this page is about the tiny little count queen of std::match_results, and sheβs serving main character energy π
πΈ NAME πΈ
std::match_results::size - std::match_results::size π
β yes bestie, the NAME line said it twice and meant it, iconic repetitive behavior, we love a consistent brand π
π Synopsis π
okay so the signature is highkey short and C++11-coded:
size_type size() const noexcept; (since C++11)
Returns the number of submatches, i.e. std::distance(begin(), end()) β literally just the distance from begin() to end(), no cap β¨
Returns 0 if *this does not represent the result of a successful match. Zero. None. The match said no π
π¦ Parameters π¦
(none) β not a single parameter, she takes no arguments, sheβs independent like that π
π Return value π
The number of submatches. Thatβs it. Thatβs the return value, bestie β¨
π₯ Complexity π₯
Constant. O(1) energy, periodt β no loops, no drama, just constant vibes β
π Example π
okay so hereβs the code, copy it exactly and watch the little count queen do her thing π§
// Run this code
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::regex re("a(a)*b");
std::string target("aaab");
std::smatch sm;
std::cout << sm.size() << '\n';
std::regex_match(target, sm, re);
std::cout << sm.size() << '\n';
}
π Output π
0
2
two lines, zero then two, no cap π
π See also π
beginβ returns iterator to the beginning of the list of sub-matches (public member function)cbeginβ public member functionendβ returns iterator to the end of the list of sub-matches (public member function)cendβ public member function
these are the sibling functions, the whole squad π«Ά
mwah π thatβs the tea from http://cppreference.com, dated 2024.06.10, on the std::match_results::size(3) page β go count your submatches, bestie π
π¦ 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