C++ 函式庫 - logical_not



描述

這是一個邏輯非函式物件類和一元函式物件類,其呼叫返回對其引數進行邏輯“非”運算的結果(如運算子!返回的結果)。

宣告

以下是 std::logical_not 的宣告。

template <class T> struct logical_not;

C++11

template <class T> struct logical_not;

引數

T − 它是函式呼叫引數和返回值的型別。

返回值

異常

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
functional.htm
廣告