21 Strings library [strings]

21.3 String classes [string.classes]

21.3.3 Class template basic_­string [basic.string]

21.3.3.8 String operations [string.ops]

21.3.3.8.4 basic_­string​::​compare [string.compare]

template<class T> constexpr int compare(const T& t) const noexcept(see below);
Constraints:
  • is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true and
  • is_­convertible_­v<const T&, const charT*> is false.
Effects: Equivalent to: return basic_­string_­view<charT, traits>(*this).compare(t);
Remarks: The expression inside noexcept is equivalent to is_­nothrow_­convertible_­v<const T&, basic_­string_­view<charT, traits>>.
template<class T> constexpr int compare(size_type pos1, size_type n1, const T& t) const;
Constraints:
  • is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true and
  • is_­convertible_­v<const T&, const charT*> is false.
Effects: Equivalent to: return basic_string_view<charT, traits>(*this).substr(pos1, n1).compare(t);
template<class T> constexpr int compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos) const;
Constraints:
  • is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true and
  • is_­convertible_­v<const T&, const charT*> is false.
Effects: Equivalent to: basic_string_view<charT, traits> s = *this, sv = t; return s.substr(pos1, n1).compare(sv.substr(pos2, n2));
constexpr int compare(const basic_string& str) const noexcept;
Effects: Equivalent to: return compare(basic_­string_­view<charT, traits>(str));
constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;
Effects: Equivalent to: return compare(pos1, n1, basic_­string_­view<charT, traits>(str));
constexpr int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const;
Effects: Equivalent to: return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
constexpr int compare(const charT* s) const;
Effects: Equivalent to: return compare(basic_­string_­view<charT, traits>(s));
constexpr int compare(size_type pos, size_type n1, const charT* s) const;
Effects: Equivalent to: return compare(pos, n1, basic_­string_­view<charT, traits>(s));
constexpr int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
Effects: Equivalent to: return compare(pos, n1, basic_­string_­view<charT, traits>(s, n2));