not2 [C++ Reference]
Keywords: stl,functional,not2
Date: 2009-12-21T18:41:06-0800

# not2

    function template<functional>template <class Predicate>
      binary_negate<Predicate> not2 (const Predicate& pred);

##### Return negation of binary function object

This function constructs a function object that has the opposite behavior of pred (its argument, another function object).

Function objects are objects whose class defines member function operator(). 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.

The function object returned by not2 has its operator() defined such that it returns true when pred would return false, and false when pred would return true.

It is defined with the same behavior as:

     template <class Predicate>
      binary_negate<Predicate> not2 (const Predicate& pred)
    {
      return binary_negate<Predicate>(pred);
    }

not2 is specifically designed to negate function objects (predicates) derived from binary_function (members first_argument_type and second_argument_type are required). For unary function objects, see not1.

### Parameters

### Predicate

Binary function object derived from binary_function.

# Return value

A binary function object with the opposite behavior of pred. binary_negate is a type derived from binary_function.

# Example

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

    int main () {
      int foo[] = {10,20,30,40,50};
      int bar[] = {0,15,30,45,60};
      pair<int*,int*> firstmatch,firstmismatch;
      firstmismatch=mismatch (foo, foo+5, bar, equal_to<int>() );
      firstmatch=mismatch (foo, foo+5, bar, not2(equal_to<int>()) );
      cout << "First mismatch in bar is " << *firstmismatch.second << "\n";
      cout << "First match in bar is " << *firstmatch.second << "\n";
      return 0;
    }

    First mismatch in bar is 0
    First match in bar is 30