logical_or in C++
Last Updated :
05 Sep, 2018
logical_or in C++ is a binary function object class which returns the result of the logical “or” operation between its two arguments (as returned by operator ||).
Syntax:
template struct logical_or : binary_function
{
T operator() (const T& a, const T& b) const {return a||b;}
};
Parameters: (T)Type of the arguments and return type of the function call. The type shall support the operation (binary operator||).
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()
{
int z[] = { 1, 0, 1, 0 };
int y[] = { 1, 1, 0, 0 };
int n = 4;
int result[n];
transform(z, z + n, y,
result, logical_or< int >());
cout<< "Logical OR:\n" ;
for ( int i = 0; i < n; i++)
cout << z[i] << " OR " << y[i]
<< " = " << result[i] << "\n" ;
return 0;
}
|
Output:
Logical OR:
1 OR 1 = 1
0 OR 1 = 1
1 OR 0 = 1
0 OR 0 = 0
Share your thoughts in the comments
Please Login to comment...