Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

logical_not

类模板  <functional>

template <class T> struct logical_not;

逻辑非函数对象类
一元函数对象类,其调用将返回对其实参进行逻辑“非”操作的结果(与operator !返回的结果相同)。

一般来说,函数对象是定义了成员函数operator()的类的实例。该成员函数允许使用与函数调用相同的语法来使用对象。

它的行为定义如下:

C++98
template <class T> struct logical_not : unary_function <T,bool> {
  bool operator() (const T& x) const {return !x;}
};

☲  模板参数


T
函数调用要比较的参数的类型。
类型应支持操作(operator!)。

☲  成员类型


成员类型 定义 注释
argument_type T 成员operator()中参数的类型
result_type bool 成员operator()返回的类型

☲  成员函数



T operator() (const T& x)
成员函数,返回参数的逻辑非(!x)。

☣  示例



// logical_not example
#include <iostream>     // std::cout, std::boolalpha
#include <functional>   // std::logical_not
#include <algorithm>    // std::transform

int main () {
  bool values[] = {true,false};
  bool result[2];
  std::transform (values, values+2, result, std::logical_not<bool>());
  std::cout << std::boolalpha << "Logical NOT:\n";
  for (int i=0; i<2; i++)
    std::cout << "NOT " << values[i] << " = " << result[i] << "\n";
  return 0;
}

输出:
Logical NOT:
NOT true = false
NOT false = true

🍄  另请参阅



logical_and 逻辑与函数对象类(类模板)
logical_or 逻辑或函数对象类(类模板)
unary_function 一元函数对象基类 (类模板)

联系我们 免责声明 关于CandCplus 网站地图