std::experi...iew::compare(3)

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

🌟 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. (1) (library fundamentals TS)
constexpr int compare(basic_string_view v) const noexcept;
  1. (2) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1,
                      basic_string_view v) const
  1. (3) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1,
                      basic_string_view v,
                      size_type pos2, size_type count2) const;
  1. (4) (library fundamentals TS)
constexpr int compare(const CharT* s) const;
  1. (5) (library fundamentals TS)
constexpr int compare(size_type pos1, size_type count1, const CharT* s) const;
  1. (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. πŸŽ€

  1. The length rlen of the sequences to compare is the smaller of size() and v.size(). The function compares the two views by calling traits::compare(data(), v.data(), rlen), and returns a value according to the following table. Table vibes, but make it bullet points:
  • Return value <0 β€” condition Traits::compare(data(), v.data(), rlen) < 0 β€” result: this is less than v
  • Return value <0 β€” condition size() < v.size() β€” result: this is less than v
  • Return value 0 β€” condition Traits::compare(data(), v.data(), rlen) == 0 plus size() == v.size() β€” result: this is equal to v
  • Return value >0 β€” condition size() > v.size() β€” result: this is greater than v
  • Return value >0 β€” condition Traits::compare(data(), v.data(), rlen) > 0 β€” result: this is greater than v
  1. Equivalent to substr(pos1, count1).compare(v).
  2. Equivalent to substr(pos1, count1).compare(v.substr(pos2, count2)).
  3. Equivalent to compare(basic_string_view(s)).
  4. Equivalent to substr(pos1, count1).compare(basic_string_view(s)).
  5. Equivalent to substr(pos1, count1).compare(basic_string_view(s, count2)).

🌸 Parameters 🌸

  • v β€” view to compare
  • s β€” pointer to the character string to compare to
  • count1 β€” number of characters of this view to compare
  • pos1 β€” position of the first character in this view to compare
  • count2 β€” number of characters of the given view to compare
  • pos2 β€” 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 πŸ”₯

  1. 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