class template
<functional>

std::logical_not

template <class T> struct logical_not;
Logical NOT function object class
Unary function object class whose call returns the result of the logical "not" operation on its argument (as returned by operator !).

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 function call.

It is defined with the same behavior as:

1
2
3
template <class T> struct logical_not : unary_function <T,bool> {
  bool operator() (const T& x) const {return !x;}
};

1
2
3
4
5
template <class T> struct logical_not {
  bool operator() (const T& x) const {return !x;}
  typedef T argument_type;
  typedef bool result_type;
};


Template parameters

T
Type of the argument passed to the functional call.
The type shall support the operation (operator!).

Member types

member typedefinitionnotes
argument_typeTType of the argument in member operator()
result_typeboolType returned by member operator()

Member functions

bool operator() (const T& x)
Member function returning logical not of its argument (!x).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// logical_not example
#include <iostream>     // std::cout, std::boolalpha
#include <functional>   // std::logical_not
#include <algorithm>    // std::transform

int main () {
  bool values[] = {true,false};
  bool result[2];
  std::transform (values, values+2, result, std::logical_not<bool>());
  std::cout << std::boolalpha << "Logical NOT:\n";
  for (int i=0; i<2; i++)
    std::cout << "NOT " << values[i] << " = " << result[i] << "\n";
  return 0;
}


Output:

Logical NOT:
NOT true = false
NOT false = true

See also