std::experi...iew::compare(3)
π NAME π
std::experimental::basic_string_view::compare β that's the function, that's the whole name, no notes. This is the std::experi...iew::compare(3) page from the C++ Standard Libary manual, and we are in the library fundamentals TS era. π
β¨
β¨ Synopsis β¨
okay so all of these are constexpr and they're all labelled (library fundamentals TS). Here's the overload lineup, bestie:
(1) (library fundamentals TS)
constexpr int compare(basic_string_view v) const noexcept;
(2) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1,
basic_string_view v) const
(3) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1,
basic_string_view v,
size_type pos2, size_type count2) const;
(4) (library fundamentals TS)
constexpr int compare(const CharT* s) const;
(5) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1, const CharT* s) const;
(6) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const;
Compares two character sequences. Iconic behavior, honestly. π
- The length
rlenof the sequences to compare is the smaller ofsize()andv.size(). The function compares the two views by callingtraits::compare(data(), v.data(), rlen), and returns a value according to the following table. Table vibes, but make it bullet points:
- Return value
<0β conditionTraits::compare(data(), v.data(), rlen) < 0β result: this is less thanv - Return value
<0β conditionsize() < v.size()β result: this is less thanv - Return value
0β conditionTraits::compare(data(), v.data(), rlen) == 0plussize() == v.size()β result: this is equal tov - Return value
>0β conditionsize() > v.size()β result: this is greater thanv - Return value
>0β conditionTraits::compare(data(), v.data(), rlen) > 0β result: this is greater thanv
- Equivalent to
substr(pos1, count1).compare(v). - Equivalent to
substr(pos1, count1).compare(v.substr(pos2, count2)). - Equivalent to
compare(basic_string_view(s)). - Equivalent to
substr(pos1, count1).compare(basic_string_view(s)). - Equivalent to
substr(pos1, count1).compare(basic_string_view(s, count2)).
πΈ Parameters πΈ
vβ view to comparesβ pointer to the character string to compare tocount1β number of characters of this view to comparepos1β position of the first character in this view to comparecount2β number of characters of the given view to comparepos2β position of the first character of the given view to compare
π« Return value π«
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence. That's the whole mood ring of comparison results. π¦
π₯ Complexity π₯
- Linear in the number of characters compared.
π¦ See also π¦
operator==operator!=operator<,operator>,operator<=,operator>=β lexicographically compares two views (function template)
π Category π
- Noindexed pages
source/version/date moment, bestie: http://cppreference.com, 2024.06.10, page std::experi...iew::compare(3). Mwah πβ¨π«Ά
π¦ 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