Open In App

logical_or in C++

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
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(): CPP
#include <bits/stdc++.h>
using namespace std;

int main()
{
    // First array
    int z[] = { 1, 0, 1, 0 };

    // Second array
    int y[] = { 1, 1, 0, 0 };
    int n = 4;
    // Result array
    int result[n];

    // transform applies logical_or
    // on both the array
    transform(z, z + n, y, 
           result, logical_or<int>());

    cout<< "Logical OR:\n";
    for (int i = 0; i < n; i++)

        // Printing the result array
        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

Practice Tags :

Similar Reads