...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Compare a string with the string.
template< typename T> constexpr int compare( size_type pos1, size_type count1, const T& t, size_type pos2, size_type count2 = npos) const;
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.
Linear.
Strong guarantee.
Type |
Description |
---|---|
|
The type of the object to convert. |
std::is_convertible<const T&, string_view>::value && !std::is_convertible<const T&, const_pointer>::value.
The result of lexicographically comparing sub1
and sub2
.
Name |
Description |
---|---|
|
The index at which to begin the substring in the string. |
|
The length of the substring in the string. |
|
The string to compare. |
|
The index at which to begin the substring in the string view. |
|
The length of the substring in the string view. |