C++ 函式庫 - logical_or



描述

它是一個邏輯或函式物件類和二元函式物件類,其呼叫返回其兩個引數之間邏輯“或”運算的結果(如運算子 || 返回的結果)。

宣告

以下是 std::logical_or 的宣告。

template <class T> struct logical_or;

C++11

template <class T> struct logical_or;

引數

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

返回值

異常

noexcep − 它不丟擲任何異常。

示例

以下示例說明了 std::logical_or。

#include <iostream>
#include <functional>
#include <algorithm>

int main () {
   bool foo[] = {true,true,false,false};
   bool bar[] = {true,false,true,false};
   bool result[4];
   std::transform (foo, foo+4, bar, result, std::logical_or<bool>());
   std::cout << std::boolalpha << "Logical OR example as shown below:\n";
   for (int i=0; i<4; i++)
      std::cout << foo[i] << " OR " << bar[i] << " = " << result[i] << "\n";
   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

Logical OR example as shown below:
true OR true = true
true OR false = true
false OR true = true
false OR false = false
functional.htm
廣告

© . All rights reserved.