CppDS.com

C++ 98 11 14 17 20 手册

std::lexicographical_compare_three_way

来自cppreference.com
< cpp‎ | algorithm
 
 
算法库
有制约算法及范围上的算法 (C++20)
有制约算法: std::ranges::copy, std::ranges::sort, ...
执行策略 (C++17)
不修改序列的操作
(C++11)(C++11)(C++11)
(C++17)
lexicographical_compare_three_way
(C++20)

修改序列的操作
未初始化存储上的操作
划分操作
排序操作
(C++11)
二分搜索操作
集合操作(在已排序范围上)
堆操作
(C++11)
最小/最大操作
(C++11)
(C++17)

排列
数值运算
C 库
 
定义于头文件 <algorithm>
template< class InputIt1, class InputIt2, class Cmp >

constexpr auto lexicographical_compare_three_way( InputIt1 first1, InputIt1 last1,
                                                  InputIt2 first2, InputIt2 last2,
                                                  Cmp comp)

-> decltype(comp(*first1, *first2));
(1) (C++20 起)
template< class InputIt1, class InputIt2 >

constexpr auto lexicographical_compare_three_way( InputIt1 first1, InputIt1 last1,

                                                  InputIt2 first2, InputIt2 last2);
(2) (C++20 起)

用三路比较,以字典序比较二个范围 [first1, last1)[first2, last2) ,并产生最强可应用比较类别类型的结果。

1) 表现为定义如下:
for ( ; first1 != last1 && first2 != last2; void(++first1), void(++first2) )
    if (auto cmp = comp(*first1, *first2); cmp != 0)
        return cmp;
 
return first1 != last1 ? std::strong_ordering::greater :
       first2 != last2 ? std::strong_ordering::less :
                         std::strong_ordering::equal;
2) 表现为定义如下:
return std::lexicographical_compare_three_way(
    first1, last1, first2, last2, std::compare_three_way());

参数

first1, last1 - 要检验的第一元素范围
first2, last2 - 要检验的第二元素范围
comp - 函数对象类型。若其返回类型不是三个比较类别类型( strong_orderingweak_orderingpartial_ordering )之一则行为未定义。
类型要求
-
InputIt1, InputIt2 必须满足遗留输入迭代器 (LegacyInputIterator) 的要求。

返回值

定义如上的比较类别类型的值。

示例

参阅

当一个范围按字典顺序小于另一个范围时,返回 true
(函数模板)
实现 x <=> y 的函数对象
(类)
关闭