目录

logical_and

描述 (Description)

它是一个逻辑AND函数对象类和二进制函数对象类,其调用返回其两个参数之间的逻辑“和”操作的结果(由operator &&返回)。

声明 (Declaration)

以下是std :: logical_and的声明。

template <class T> struct logical_and;

C++11

template <class T> struct logical_and;

参数 (Parameters)

T - 它是函数调用的参数和返回类型的一种类型。

返回值 (Return Value)

没有

异常 (Exceptions)

noexcep - 它不会抛出任何异常。

例子 (Example)

在下面的例子中解释了std :: logical_and。

#include <iostream>
#include <functional>
#include <algorithm>
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_and<bool>());
   std::cout << std::boolalpha << "Logical AND:\n";
   for (int i=0; i<4; i++)
      std::cout << foo[i] << " AND " << bar[i] << " = " << result[i] << "\n";
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Logical AND:
true AND true = true
false AND true = false
true AND false = false
false AND false = false
↑回到顶部↑
WIKI教程 @2018