class template
std::logical_not
<functional>
template <class T> struct logical_not;
Logical NOT function object class
This class defines function objects for the
"not" 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_not has its
operator() member defined such that it returns
true if its argument is
false, and
false if its argument is
true, inverting its value.
This class is derived from
unary_function and is defined as:
1 2 3 4
|
template <class T> struct logical_not : unary_function <T,bool> {
bool operator() (const T& x) const
{return !x;}
};
|
Objects of this class can be used with several standard
algorithms (see
algorithm).
Members
- bool operator() (const T& x)
- Member function returning the result of !x.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// logical_not example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main () {
bool values[] = {true,false};
bool result[2];
transform (values, values+2, result, logical_not<bool>() );
cout << boolalpha << "Logical NOT:\n";
for (int i=0; i<2; i++)
cout << "NOT " << values[i] << " = " << result[i] << "\n";
return 0;
}
|
Output:
Logical NOT:
NOT true = false
NOT false = true
|
See also
- logical_and
- Logical AND function object class (class template
)
- logical_or
- Logical OR function object class (class template
)
- unary_function
- Unary function object base class (class template)