std::sub_match::compare(3)
π std::sub_match::compare β okay bestie, let's get into it
So this is std::sub_match::compare from the C++ Standard Library, and honestly? It's a little niche, but it's ours now, so let's understand it together π«Ά
β¨ Synopsis β¨
int compare( const sub_match& m ) const; (1) (since C++11)
int compare( const string_type& s ) const; (2) (since C++11)
int compare( const value_type* c ) const; (3) (since C++11)
Three whole overloads, all since C++11, all const, all returning int. Iconic.
- Compares two
sub_matchdirectly, by comparing their underlying character sequences. Literally equivalent tostr().compare(m.str()). That's it, that's the whole vibe. - Compares a
sub_matchwith astd::basic_string. Equivalent tostr().compare(s). - Compares a
sub_matchwith a null-terminated sequence of the underlying character type, pointed to bys. Equivalent tostr().compare(c).
Real talk though: this function is infrequently used directly by application code. Like, nobody's out here calling it in the group chat. Instead, one of the non-member comparison operators gets used. That's the main character. compare is just vibing backstage π
π Parameters π
mβ a reference to anothersub_match, i.e. the other one of these guyssβ a reference to a string you're comparing againstcβ a pointer to a null-terminated character sequence of the underlyingvalue_type, the thing you're comparing against
πΈ Return value πΈ
Here's the vibe check, spelled out in numbers:
- less than zero if this
sub_matchis less than the other character sequence - zero if both underlying character sequences are equal (slay, a match π)
- greater than zero if this
sub_matchis greater than the other character sequence
So it's the classic three-way situation β negative, zero, positive. No cap.
π¦ Example π¦
This section is incomplete
Reason: no example
π not me finding out the example section is literally empty. Bestie... the docs said "no example" and I felt that. If you want, go write one β the page is begging for it π
π§ See also π§
compareβ compares two strings (public member function ofstd::basic_string<CharT,Traits,Allocator>)strβ converts to the underlying string typeoperator string_typeβ converts to the underlying string type (public member function)operator==,operator!=,operator<,operator<=,operator>,operator>=,operator<=>(removed in C++20) β compares asub_matchwith anothersub_match, a string, or a character (function template) β and note that<=>is the C++20 one π
Also, just so nobody comes for me: this page is filed under the category Todo no example. Not a vibe, but we move.
Alright, that's the whole thing! This page came to you from cppreference.com, dated 2024.06.10 β big love to them for the source and the version, and go off, bestie, you now understand std::sub_match::compare ππ₯π
π¦ 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