Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
basic_static_string::compare (9 of 9 overloads)

Compare a string with the string.

Synopsis
template<
    [role red error.param neither has a declname nor a 'class ' prefix in the type][role red error.param neither has a declname nor a 'class ' prefix in the type][role red error.param neither has a declname nor a 'class ' prefix in the type][role red error.param neither has a declname nor a 'class ' prefix in the type]>
constexpr int
compare(
    size_type pos1,
    size_type count1,
    const T& t,
    size_type pos2,
    size_type count2 = npos) const;
Description

Let sub1 be substr(pos1, count1), sub2 be string_view_type(t).substr(pos2, count2), and comp be traits_type::compare(sub1.data(), sub2.data(), std::min(sub1.size(), sub2.size()). If comp != 0, then the result is comp. Otherwise, the result is 0 if sub1.size() == sub2.size(), -1 if sub1.size() < sub2.size(), and 1 otherwise.

Complexity

Linear.

Exception Safety

Strong guarantee.

Template Parameters

Type

Description

T

The type of the object to convert.

Constraints
std::is_convertible<const T&, string_view>::value &&
!std::is_convertible<const T&, const_pointer>::value.
Return Value

The result of lexicographically comparing sub1 and sub2.

Parameters

Name

Description

pos1

The index at which to begin the substring in the string.

count1

The length of the substring in the string.

t

The string to compare.

pos2

The index at which to begin the substring in the string view.

count2

The length of the substring in the string view.


PrevUpHomeNext