[#bsl-basic_string-0fb-compare-04d]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-0fb.adoc[basic&lowbar;string&lt;char&gt;]::compare
:relfileprefix: ../../
:mrdocs:

`compare` overloads

== Synopses

Declared in `&lt;bslstl&lowbar;string&period;h&gt;`

Lexicographically compare this string with the specified `other` string, and return a negative value if this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0fb/compare-06e.adoc[compare](xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;] const& other) const noexcept;
----

[.small]#xref:bsl/basic_string-0fb/compare-06e.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with the specified null&hyphen;terminated `other` string (of length `CHAR&lowbar;TRAITS&colon;&colon;length(other)`), and return a negative value if this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0fb/compare-01.adoc[compare](char const* other) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-01.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with the specified `other`, and return a negative value if this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period; The behavior is undefined unless the conversion from `STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE` to `bsl&colon;&colon;basic&lowbar;string&lowbar;view&lt;CHAR&lowbar;TYPE, CHAR&lowbar;TRAITS&gt;` does not throw any exception&period; Note that this behavior differs from the behavior implemented in the standard container, where the following noexcept specification is used&colon; &grave; noexcept( std&colon;&colon;is&lowbar;nothrow&lowbar;convertible&lowbar;v&lt;const T&amp;, std&colon;&colon;basic&lowbar;string&lowbar;view&lt;CharT, Traits&gt; &gt;) &grave;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
xref:bsl/basic_string-0fb/compare-063.adoc[compare](STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other) const noexcept(true);
----

[.small]#xref:bsl/basic_string-0fb/compare-063.adoc[_» more&period;&period;&period;_]#

Lexicographically compare the substring of this string of the specified `lhsNumChars` length starting at the specified `lhsPosition` (or the suffix of this string starting at `lhsPosition` if `lhsPosition &plus; lhsNumChars &gt; length()`) with the specified null&hyphen;terminated `other` string (of length `CHAR&lowbar;TRAITS&colon;&colon;length(other)`), and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; Throw `out&lowbar;of&lowbar;range` if `lhsPosition &gt; length()`&period; See &lcub;Lexicographical Comparisons&rcub;&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0fb/compare-041.adoc[compare](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsNumChars,
    char const* other) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-041.adoc[_» more&period;&period;&period;_]#

Lexicographically compare the substring of this string of the specified `numChars` length starting at the specified `position` (or the suffix of this string starting at `position` if `position &plus; numChars &gt; length()`) with the specified `other` string, and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0fb/compare-0b8.adoc[compare](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;] const& other) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-0b8.adoc[_» more&period;&period;&period;_]#

Lexicographically compare the substring of this string of the specified `numChars` length starting at the specified `position` (or the suffix of this string starting at `position` if `position &plus; numChars &gt; length()`) with the specified `other`, and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
xref:bsl/basic_string-0fb/compare-0bc.adoc[compare](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-0bc.adoc[_» more&period;&period;&period;_]#

Lexicographically compare the substring of this string of the specified `lhsNumChars` length starting at the specified `lhsPosition` (or the suffix of this string starting at `lhsPosition` if `lhsPosition &plus; lhsNumChars &gt; length()`) with the specified `other` string of the specified `otherNumChars` length, and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; Throw `out&lowbar;of&lowbar;range` if `lhsPosition &gt; length()`&period; See &lcub;Lexicographical Comparisons&rcub;&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0fb/compare-05.adoc[compare](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsNumChars,
    char const* other,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] otherNumChars) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-05.adoc[_» more&period;&period;&period;_]#

Lexicographically compare the substring of this string of the specified `lhsNumChars` length starting at the specified `lhsPosition` (or the suffix of this string starting at `lhsPosition` if `lhsPosition &plus; lhsNumChars &gt; length()`) with the substring of the specified `other` string of the optionally specified `otherNumChars` length starting at the specified `otherPosition` (or the suffix of `other` starting at `otherPosition` if `otherPosition &plus; otherNumChars &gt; other&period;length()`)&period; If `numChars` is not specified, `npos` is used&period; Return a negative value if the indicated substring of this string is less than the indicated substring of `other`, a positive value if it is greater than the indicated substring of `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; Throw `out&lowbar;of&lowbar;range` if `lhsPosition &gt; length()` or `otherPosition &gt; other&period;length()`&period; See &lcub;Lexicographical Comparisons&rcub;&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0fb/compare-0b5.adoc[compare](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsNumChars,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;] const& other,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] otherPosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] otherNumChars = npos) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-0b5.adoc[_» more&period;&period;&period;_]#

Lexicographically compare the substring of this string of the specified `lhsNumChars` length starting at the specified `lhsPosition` (or the suffix of this string starting at `lhsPosition` if `lhsPosition &plus; lhsNumChars &gt; length()`) with the substring of the specified `other` of the optionally specified `otherNumChars` length starting at the specified `otherPosition` (or the suffix of `other` starting at `otherPosition` if `otherPosition &plus; otherNumChars &gt; other&period;length()`)&period; If `numChars` is not specified, `npos` is used&period; Return a negative value if the indicated substring of this string is less than the indicated substring of `other`, a positive value if it is greater than the indicated substring of `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period; Throw `out&lowbar;of&lowbar;range` if `lhsPosition &gt; length()` or `otherPosition &gt; other&period;length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
xref:bsl/basic_string-0fb/compare-064.adoc[compare](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] lhsNumChars,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] otherPosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] otherNumChars = npos) const;
----

[.small]#xref:bsl/basic_string-0fb/compare-064.adoc[_» more&period;&period;&period;_]#


[.small]#Created with https://www.mrdocs.com[MrDocs]#
