logical_and in C++
Last Updated :
05 Sep, 2018
logical_and in C++ is a binary function object class which returns the result of the logical “and” operation between its two arguments (as returned by operator &&).
Syntax:
template struct logical_and : binary_function
{
T operator() (const T& a, const T& b) const {return a&b&}
};
Parameters: (T)Type of the arguments and the return type of the function call.
Member types:
- a: Type of the first argument in member operator()
- b: Type of the second argument in member operator()
- result_type: Type returned by member operator()
Below is the program to implement logical_and using std::transform():
#include <bits/stdc++.h>
using namespace std;
int main()
{
bool z[] = { true , false , true , false , true };
bool y[] = { true , true , false , false , true };
int n = 5;
bool result[n];
transform(z, z + n, y, result,
logical_and< bool >());
cout << "Logical AND:\n" ;
for ( int i = 0; i < n; i++)
cout << z[i] << " AND " << y[i]
<< " = " << result[i] << "\n" ;
return 0;
}
|
Output:
Logical AND:
1 AND 1 = 1
0 AND 1 = 0
1 AND 0 = 0
0 AND 0 = 0
1 AND 1 = 1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...