std::char_traits<char>::compare, std::char_traits<wchar_t>::compare, std::char_traits<char8_t>::compare, std::char_traits<char16_t>::compare, std::char_traits<char32_t>::compare
From cppreference.com
static int compare( const char_type* s1, const char_type* s2,
std::size_t count );
|
(constexpr since C++17) | |
Compares the first count characters of the character strings s1 and s2. The comparison is done lexicographically.
If count is zero, strings are considered equal.
See CharTraits for the general requirements on character traits for X::compare.
Parameters
| s1, s2 | - | pointers to character strings to compare |
| count | - | the number of characters to compare from each character string |
Return value
Negative value if s1 is less than s2.
0 if s1 is equal to s2.
Positive value if s1 is greater than s2.
Complexity
Linear in count.
Note
The return value is determined by lexicographical order. Formally, the return value is determined as follows:
- If for each
iin[0,count),eq(s1[i], s2[i])istrue, then return0. - Otherwise, if for some
iin[0,count),lt(s1[i], s2[i])istrueand for everyjin[0,i),eq(s1[j], s2[j])istrue, then return a negative value. - Otherwise, return a positive value.
See also
[static] |
compares two characters (public static member function) |