cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Miscellaneous : functional : logical_or
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
functional
iterator
memory
utility
functional
binary_function
unary_function
operator classes:
· divides
· equal_to
· greater
· greater_equal
· less
· less_equal
· logical_and
· logical_not
· logical_or
· minus
· modulus
· multiplies
· negate
· not_equal_to
· plus
adaptor functions:
· bind1st
· bind2nd
· mem_fun
· mem_fun_ref
· not1
· not2
· ptr_fun
types:
· binary_negate
· binder1st
· binder2nd
· const_mem_fun1_ref_t
· const_mem_fun1_t
· const_mem_fun_ref_t
· const_mem_fun_t
· mem_fun1_ref_t
· mem_fun1_t
· mem_fun_ref_t
· mem_fun_t
· pointer_to_binary_funct...
· pointer_to_unary_function
· unary_negate

-

logical_or class template
template <class T> struct logical_or;
<functional>

Logical OR function object class

This class defines function objects for the "or" logical operation (||).

Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a regular function call, and therefore it can be used in templates instead of a pointer to a function.

logical_or has its operator() member defined such that it returns true if either (or both) of its arguments are true (using operator||), and false otherwise (when neither of the arguments is true).

This class is derived from binary_function and is defined as:

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

Objects of this class can be used with several standard algorithms (see algorithm).

Members

T operator() (const T& x, const T& y)
Member function returning the result of x||y.

Example

// logical_or example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

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

Output:


Logical OR:
true OR true = true
false OR true = true
true OR false = true
false OR false = false

See also

logical_and Logical AND function object class (class template)
logical_not Logical NOT function object class (class template)
binary_function Binary function object base class (class template)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us