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

std::

logical_or

类模板  <functional>

template <class T> struct logical_or;

逻辑或函数对象类
二元函数对象类,其调用将返回两个参数之间的逻辑“或”操作的结果(由操作符||返回)。

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

它的行为定义如下:

C++98
template <class T> struct logical_or : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x||y;}
};

☲  模板参数


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

☲  成员类型


成员类型 定义 注释
first_argument_type T 成员operator()中第一个参数的类型
second_argument_type T 成员operator()中第二个参数的类型
result_type bool 成员operator()返回的类型

☲  成员函数



T operator() (const T& x, const T& y)
成员函数,返回其两个参数是否都为真(x||y).

☣  示例



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

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

输出:
Logical OR:
true OR true = true
false OR true = true
true OR false = true
false OR false = false

🍄  另请参阅



logical_and 逻辑与函数对象类(类模板)
logical_not 逻辑非函数对象类(类模板)
binary_function 二元函数对象基类 (类模板)

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