std::sub_ma...b_match::str(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ 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