名稱空間
變體
操作

std::less<void>

來自 cppreference.com
 
 
 
函式物件
函式呼叫
(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 的一個特化,其引數和返回型別是推導的。

目錄

[編輯] 巢狀型別

巢狀型別 定義
is_transparent 未指定

[編輯] 成員函式

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).

若呼叫內建的指標比較運算子,則結果與對指標的實現定義嚴格全序一致。

[編輯] 異常

可能丟擲實現定義的異常。

[編輯] 示例

#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));
}

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 2562 C++98 指標全序可能不一致 保證一致