std::logical_not_C++中文网

定义于头文件 <functional>

template< class T >
struct logical_not;

(C++14 前)

template< class T = void >
struct logical_not;

(C++14 起)

实现逻辑非(逻辑取反)的函数对象。等效地调用类型 Toperator!

特化

标准库提供 std::logical_not 在不指定 T 时的特化,它使得参数类型和返回类型留待推导。

(C++14 起)

成员类型

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

成员函数

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

std::logical_not::operator()

bool operator()( const T& arg ) const;

(C++14 前)

constexpr bool operator()( const T& arg ) const;

(C++14 起)

返回 arg 的逻辑非。

参数

返回值

!arg 的结果。

异常

(无)

可能的实现

const bool operator()(const T &arg) const 
{
    return !arg;
}