std::regex_...*,operator->(3)

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

πŸ’… std::regex_...*,operator->(3) πŸ’…

Okay bestie, this is the manual page std::regex_...*,operator->(3) from the C++ Standard Libary β€” and yes, that's the header's spelling, not me πŸ’€. It's all about the std::regex_iterator duo operator* and operator->, and it's giving tiny-accessor, big-match-results energy ✨.


πŸŽ€ NAME πŸŽ€

std::regex_iterator::operator*,operator-> β€” std::regex_iterator::operator*,operator->

Yes, the page literally lists it twice like that. Not me, the manpage. πŸ’€


✨ Synopsis ✨

const value_type& operator*() const;  (1) (since C++11)
const value_type* operator->() const; (2) (since C++11)

Extracts the current std::match_results from a regex_iterator. Slay. πŸ’–


πŸ’– Return value πŸ’–

  1. Returns a reference to the current std::match_results.
  2. Returns a pointer to the current std::match_results.

So operator* hands you the ref, and operator-> hands you the pointer. Both iconic, both since C++11. 🫢


🌸 Example 🌸

// Run this code

#include <iostream>
#include <regex>
#include <string>

int main()
{
    std::string hay{"1.1a2b3cjk34"};
    std::regex needle("[1234]");
    using Ri = std::regex_iterator<std::string::iterator>;
    for (Ri it{hay.begin(), hay.end(), needle}, last{}; it != last;
       ++it)
        std::cout << it->str();
    std::cout << '\n';
}

Bestie, this example is lowkey cute: it walks hay with the needle regex [1234], and prints each match using it->str(). The operator-> is doing main character work here. πŸ‘‘πŸ”₯


πŸ¦‹ Output πŸ¦‹

112334

That's the whole page, bestie. Source/version: http://cppreference.com Β· date: 2024.06.10 Β· footer page: std::regex_...*,operator->(3). Byeeee πŸ’…πŸŽ€
πŸ“¦ where this page comes from