命名空间
变体
操作

std::less<void>

来自 cppreference.cn
< cpp‎ | utility‎ | functional
 
 
 
函数对象
函数调用
(C++17)(C++23)
恒等函数对象
(C++20)
透明运算符包装器
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
less<>
(C++14)

旧式绑定器和适配器
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)  
(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
(直到 C++17*)(直到 C++17*)
(直到 C++17*)(直到 C++17*)

(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
 
定义于头文件 <functional>
template<>
class less<void>;
(自 C++14 起)

std::less<void>std::less 的特化,具有推导的形参与返回类型。

目录

[edit] 嵌套类型

嵌套类型 定义
is_transparent 未指定

[edit] 成员函数

operator()
测试 lhs 是否小于 rhs
(公有成员函数)

std::less<void>::operator()

template< class T, class U >

constexpr auto operator()( T&& lhs, U&& rhs ) const

    -> decltype(std::forward<T>(lhs) < std::forward<U>(rhs));

返回 std::forward<T>(lhs) < std::forward<U>(rhs) 的结果。

参数

lhs, rhs - 要比较的值

返回值

std::forward<T>(lhs) < std::forward<U>(rhs).

如果调用了比较指针的内建运算符,则结果与实现定义的指针严格全序一致。

[edit] 异常

可能抛出实现定义的异常。

[edit] 示例

#include <algorithm>
#include <functional>
 
constexpr bool strictly_negative(int lhs)
{
    return std::less<>()(lhs, 0);
}
 
int main()
{
    constexpr signed low = 010;
    constexpr unsigned high = 10;
    std::less<> less{};
    static_assert(less(low, high));
 
    constexpr static auto arr = {0, -1, -2, -3, -4, -5};
    static_assert(!std::all_of(arr.begin(), arr.end(), strictly_negative));
    static_assert(std::all_of(arr.begin() + 1, arr.end(), strictly_negative));
}

[edit] 缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 应用于 发布时的行为 正确的行为
LWG 2562 C++98 指针全序可能不一致 保证一致