C++ Functional 库 - logical_not
描述
它是一个逻辑非函数对象类和一个一元函数对象类,其调用返回对其参数的逻辑"非"操作的结果(由运算符!返回)。
声明
以下是 std::logical_not 的声明。
template <class T> struct logical_not;
C++11
template <class T> struct logical_not;
参数
T − 它是函数调用的参数类型和返回类型。
返回值
none
异常
noexcep − 它不会抛出任何异常。
示例
在下面的例子中解释了 std::logical_not。
#include <iostream>
#include <functional>
#include <algorithm>
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 Example as shown below:\n";
for (int i=0; i<2; i++)
std::cout << "NOT " << values[i] << " = " << result[i] << "\n";
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Logical NOT Example as shown below: NOT true = false NOT false = true

