[string.compare] # 27 Strings library [[strings]](./#strings) ## 27.4 String classes [[string.classes]](string.classes#string.compare) ### 27.4.3 Class template basic_string [[basic.string]](basic.string#string.compare) #### 27.4.3.8 String operations [[string.ops]](string.ops#string.compare) #### 27.4.3.8.4 basic_string​::​compare [string.compare] [🔗](#lib:compare,basic_string) `template constexpr int compare(const T& t) const noexcept(see below); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4499) *Constraints*: - [(1.1)](#1.1) is_convertible_v> istrue and - [(1.2)](#1.2) is_convertible_v isfalse[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4510) *Effects*: Equivalent to: return basic_string_view(*this).compare(t); [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4514) *Remarks*: The exception specification is equivalent tois_nothrow_convertible_v>[.](#3.sentence-1) [🔗](#lib:compare,basic_string_) `template constexpr int compare(size_type pos1, size_type n1, const T& t) const; ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4527) *Constraints*: - [(4.1)](#4.1) is_convertible_v> istrue and - [(4.2)](#4.2) is_convertible_v isfalse[.](#4.sentence-1) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4538) *Effects*: Equivalent to:return basic_string_view(*this).substr(pos1, n1).compare(t); [🔗](#lib:compare,basic_string__) `template constexpr int compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos) const; ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4554) *Constraints*: - [(6.1)](#6.1) is_convertible_v> istrue and - [(6.2)](#6.2) is_convertible_v isfalse[.](#6.sentence-1) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4565) *Effects*: Equivalent to:basic_string_view s = *this, sv = t;return s.substr(pos1, n1).compare(sv.substr(pos2, n2)); [🔗](#lib:compare,basic_string___) `constexpr int compare(const basic_string& str) const noexcept; ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4580) *Effects*: Equivalent to:return compare(basic_string_view(str)); [🔗](#lib:compare,basic_string____) `constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const; ` [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4592) *Effects*: Equivalent to:return compare(pos1, n1, basic_string_view(str)); [🔗](#lib:compare,basic_string_____) `constexpr int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const; ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4605) *Effects*: Equivalent to:return compare(pos1, n1, basic_string_view(str), pos2, n2); [🔗](#lib:compare,basic_string______) `constexpr int compare(const charT* s) const; ` [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4619) *Effects*: Equivalent to:return compare(basic_string_view(s)); [🔗](#lib:compare,basic_string_______) `constexpr int compare(size_type pos, size_type n1, const charT* s) const; ` [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4631) *Effects*: Equivalent to: return compare(pos, n1, basic_string_view(s)); [🔗](#lib:compare,basic_string________) `constexpr int compare(size_type pos, size_type n1, const charT* s, size_type n2) const; ` [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4642) *Effects*: Equivalent to: return compare(pos, n1, basic_string_view(s, n2));