Namespaces
Variants
Views
Actions

std::lexicographical_compare_3way

From cppreference.com
< cpp‎ | algorithm
 
 
Algorithm library
Execution policies (C++17)
Non-modifying sequence operations
(C++11)(C++11)(C++11)
(C++17)
lexicographical_compare_3way
(C++20)

Modifying sequence operations
Operations on uninitialized storage
Partitioning operations
Sorting operations
(C++11)
Binary search operations
Set operations (on sorted ranges)
Heap operations
(C++11)
Minimum/maximum operations
(C++11)
(C++17)
Permutations
Numeric operations
C library
 
Defined in header <algorithm>
template< class InputIt1, class InputIt2, class Cmp >

constexpr auto lexicographical_compare_3way( InputIt1 b1, InputIt1 e1,
                                             InputIt2 b2, InputIt2 e2,
                                             Cmp comp)

-> std::common_comparison_category_t<decltype(comp(*b1, *b2)), std::strong_ordering>;
(1) (since C++20)
template< class InputIt1, class InputIt2 >

constexpr auto lexicographical_compare_3way( InputIt1 b1, InputIt1 e1,

                                             InputIt2 b2, InputIt2 e2);
(2) (since C++20)

Lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison and produces a result of the strongest applicable comparison category type.

1) Behaves as if defined as follows:
for ( ; b1 != e1 && b2 != e2; void(++b1), void(++b2) )
  if (auto cmp = comp(*b1,*b2); cmp != 0)
    return cmp;
  return b1 != e1 ? std::strong_ordering::greater :
         b2 != e2 ? std::strong_ordering::less :
                    std::strong_ordering::equal;
2) Behaves as if defined as follows:
return std::lexicographical_compare_3way(b1, e1, b2, e2,
           [](const auto& t, const auto& u) {
               return std::compare_3way(t, u);
           });

Contents

[edit] Parameters

first1, last1 - the first range of elements to examine
first2, last2 - the second range of elements to examine
comp - a function object type. The behavior is undefined if its return type is not one of the five comparison category types (strong_equality, weak_equality, strong_ordering, weak_ordering, or partial_ordering)
Type requirements
-
InputIt1, InputIt2 must meet the requirements of InputIterator.

[edit] Return value

A comparison category type as defined above.

[edit] Example

[edit] See also

compares two values using three-way comparison
(function template) [edit]