std::sub_ma...b_match::str(3)
π std::sub_ma...b_match::str(3) π
hiii bestie, welcome to the C++ Standard Libary page for std::sub_ma...b_match::str(3) β yes, the title is doing a little ellipsis moment, we respect it. π
πΈ NAME πΈ
std::sub_match::operatorstring_type,std::sub_match::strβ and then, because sheβs extra, the original NAME line says the exact same thing again:std::sub_match::operatorstring_type,std::sub_match::str. yes bestie, thatβs the name, comma and all, periodt. π
β¨ Synopsis β¨
okay so hereβs the synopsis, copied exactly because we do not play with code:
operator string_type() const; (1)
string_type str() const; (2)
This whole situation converts to an object of the underlying std::basic_string type. The first version is an implicit conversion, and the second one is explicit. thatβs the difference, and itβs kind of the whole plot. π«Ά
π Parameters π
(none) β zero parameters. not a single one. she takes no arguments and still serves. π
π Return value π
Returns the matched character sequence as an object of the underlying std::basic_string type. If the matched member is false, then the empty string is returned. yes, empty string, not chaos β sheβs polite like that. π
π¦ Complexity π¦
Linear in the length of the underlying character sequence. so like, it scales with the sequence, no mystery, no cap. π
π Example π
the original literally says // Run this code, so bestieβ¦ run it. β¨
#include <cassert>
#include <iostream>
#include <regex>
#include <string>
int main()
{
const std::string html{R"("<a href="https://cppreference.com/">)"};
const std::regex re{"(http|https|ftp)://([a-z]+)\\.([a-z]{3})"};
std::smatch parts;
std::regex_search(html, parts, re);
for (std::ssub_match const& sub : parts)
{
const std::string s = sub; // (1) implicit conversion
assert(s == sub.str()); // (2)
std::cout << s << '\n';
}
}
quick vibe check: (1) is the implicit conversion, (2) is str(), and the assert is making sure they match. iconic behavior, honestly. π§
β Output β
https://cppreference.com
https
cppreference
com
bestie note: the first version is the implicit conversion, the second one is explicit β that distinction stays exactly where it is. no renaming, no merging, no invented options. π«‘
mwah π β this cutie came from http://cppreference.com, version/date 2024.06.10, and the page is std::sub_ma...b_match::str(3). slay. π
π¦ 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