[#bsl-basic_string-0e-compare-0f0] = xref:bsl.adoc[bsl]::xref:bsl/basic_string-0e.adoc[basic_string<wchar_t>]::compare :relfileprefix: ../../ :mrdocs: `compare` overloads == Synopses Declared in `<bslstl_string.h>` 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. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int xref:bsl/basic_string-0e/compare-09c.adoc[compare](xref:bsl/basic_string-0faf.adoc[basic_string<wchar_t>] const& other) const noexcept; ---- [.small]#xref:bsl/basic_string-0e/compare-09c.adoc[_» more..._]# Lexicographically compare this string with the specified null‐terminated `other` string (of length `CHAR_TRAITS::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. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int xref:bsl/basic_string-0e/compare-09f.adoc[compare](wchar_t const* other) const; ---- [.small]#xref:bsl/basic_string-0e/compare-09f.adoc[_» more..._]# 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. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. The behavior is undefined unless the conversion from `STRING_VIEW_LIKE_TYPE` to `bsl::basic_string_view<CHAR_TYPE, CHAR_TRAITS>` does not throw any exception. Note that this behavior differs from the behavior implemented in the standard container, where the following noexcept specification is used: ` noexcept( std::is_nothrow_convertible_v<const T&, std::basic_string_view<CharT, Traits> >) ` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class STRING_VIEW_LIKE_TYPE> int xref:bsl/basic_string-0e/compare-04.adoc[compare](STRING_VIEW_LIKE_TYPE const& other) const noexcept(true); ---- [.small]#xref:bsl/basic_string-0e/compare-04.adoc[_» more..._]# 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 + lhsNumChars > length()`) with the specified null‐terminated `other` string (of length `CHAR_TRAITS::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. `CHAR_TRAITS::lt` is used to compare characters. Throw `out_of_range` if `lhsPosition > length()`. See {Lexicographical Comparisons}. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int xref:bsl/basic_string-0e/compare-0bc.adoc[compare]( xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsPosition, xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsNumChars, wchar_t const* other) const; ---- [.small]#xref:bsl/basic_string-0e/compare-0bc.adoc[_» more..._]# 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 + numChars > 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. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. Throw `out_of_range` if `position > length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int xref:bsl/basic_string-0e/compare-0eb.adoc[compare]( xref:bsl/basic_string-0e/size_type.adoc[size_type] position, xref:bsl/basic_string-0e/size_type.adoc[size_type] numChars, xref:bsl/basic_string-0faf.adoc[basic_string<wchar_t>] const& other) const; ---- [.small]#xref:bsl/basic_string-0e/compare-0eb.adoc[_» more..._]# 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 + numChars > 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. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. Throw `out_of_range` if `position > length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class STRING_VIEW_LIKE_TYPE> int xref:bsl/basic_string-0e/compare-0f2.adoc[compare]( xref:bsl/basic_string-0e/size_type.adoc[size_type] position, xref:bsl/basic_string-0e/size_type.adoc[size_type] numChars, STRING_VIEW_LIKE_TYPE const& other) const; ---- [.small]#xref:bsl/basic_string-0e/compare-0f2.adoc[_» more..._]# 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 + lhsNumChars > 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. `CHAR_TRAITS::lt` is used to compare characters. Throw `out_of_range` if `lhsPosition > length()`. See {Lexicographical Comparisons}. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int xref:bsl/basic_string-0e/compare-0efa.adoc[compare]( xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsPosition, xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsNumChars, wchar_t const* other, xref:bsl/basic_string-0e/size_type.adoc[size_type] otherNumChars) const; ---- [.small]#xref:bsl/basic_string-0e/compare-0efa.adoc[_» more..._]# 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 + lhsNumChars > 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 + otherNumChars > other.length()`). If `numChars` is not specified, `npos` is used. 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. `CHAR_TRAITS::lt` is used to compare characters. Throw `out_of_range` if `lhsPosition > length()` or `otherPosition > other.length()`. See {Lexicographical Comparisons}. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int xref:bsl/basic_string-0e/compare-0ef7.adoc[compare]( xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsPosition, xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsNumChars, xref:bsl/basic_string-0faf.adoc[basic_string<wchar_t>] const& other, xref:bsl/basic_string-0e/size_type.adoc[size_type] otherPosition, xref:bsl/basic_string-0e/size_type.adoc[size_type] otherNumChars = npos) const; ---- [.small]#xref:bsl/basic_string-0e/compare-0ef7.adoc[_» more..._]# 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 + lhsNumChars > 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 + otherNumChars > other.length()`). If `numChars` is not specified, `npos` is used. 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. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. Throw `out_of_range` if `lhsPosition > length()` or `otherPosition > other.length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class STRING_VIEW_LIKE_TYPE> int xref:bsl/basic_string-0e/compare-0ba.adoc[compare]( xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsPosition, xref:bsl/basic_string-0e/size_type.adoc[size_type] lhsNumChars, STRING_VIEW_LIKE_TYPE const& other, xref:bsl/basic_string-0e/size_type.adoc[size_type] otherPosition, xref:bsl/basic_string-0e/size_type.adoc[size_type] otherNumChars = npos) const; ---- [.small]#xref:bsl/basic_string-0e/compare-0ba.adoc[_» more..._]# [.small]#Created with https://www.mrdocs.com[MrDocs]#