std::greater<void>
来自cppreference.com
< cpp | utility | functional
在标头 <functional> 定义 | ||
template<> class greater<void>; | (C++14 起) | |
std::greater<void> 是会推导形参类型和返回类型的 std::greater 特化。
目录 |
[编辑]嵌套类型
嵌套类型 | 定义 |
is_transparent | 未指定 |
[编辑]成员函数
operator() | 测试 lhs 是否比较大于 rhs (公开成员函数) |
std::greater<void>::operator()
template<class T, class U > constexprauto operator()( T&& lhs, U&& rhs )const | ||
返回 std::forward<T>(lhs)>std::forward<U>(rhs) 的结果。
参数
lhs, rhs | - | 要比较的值 |
返回值
std::forward<T>(lhs)>std::forward<U>(rhs)。
如果调用了内建的运算符比较指针,那么结果会与由实现定义的指针严格全序保持一致。
[编辑]异常
可能会抛出由实现定义的异常。
[编辑]示例
运行此代码
#include <algorithm>#include <cstdint>#include <functional> constexprbool strictly_positive(int lhs){returnstd::greater<>()(lhs, 0);} int main(){constexprstd::int64_t low =0B11;constexprstd::uint16_t high =0X11;std::greater<> greater{}; static_assert(greater(high, low)); constexprstaticauto arr ={0, 1, 2, 3, 4, 5}; static_assert(!std::all_of(arr.begin(), arr.end(), strictly_positive)); static_assert(std::all_of(arr.begin()+1, arr.end(), strictly_positive));}
[编辑]缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
---|---|---|---|
LWG 2562 | C++98 | 指针全序可能不一致 | 保证一致 |