命名空间
变体
操作

std::logical_not

来自 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)
(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 T >
struct logical_not;
(直到 C++14)
template< class T = void >
struct logical_not;
(自 C++14 起)

用于执行逻辑非(逻辑否定)的函数对象。 有效地为类型 T 调用 operator!

内容

[编辑] 特化

当未指定 T 时,标准库提供了 std::logical_not 的特化,这使得参数类型和返回类型被推导。

实现 !x 并推导参数和返回类型的函数对象
(类模板特化) [编辑]
(自 C++14 起)

[编辑] 成员类型

类型 定义
result_type (在 C++17 中弃用)(在 C++20 中移除) bool
argument_type (在 C++17 中弃用)(在 C++20 中移除) T

这些成员类型通过公开继承 std::unary_function<T, bool> 获得。

(直到 C++11)

[编辑] 成员函数

operator()
返回参数的逻辑非
(公共成员函数)

std::logical_not::operator()

bool operator()( const T& arg ) const;
(constexpr 自 C++14 起)

返回 arg 的逻辑非。

参数

arg - 要计算逻辑非的值

返回值

!arg 的结果。

[编辑] 异常

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

可能的实现

constexpr // since C++14
bool operator()(const T& arg) const 
{
    return !arg;
}