unary_negate, not1


A unary function object that returns the logical negation of executing its unary predicate. Use the associated adapter function not1() to conveniently construct a unary_negate object directly from a predicate.

Library

Standards<ToolKit>

Declaration


#include <functional>

template< class Predicate >
class unary_negate : public unary_function
  <
  typename Predicate::argument_type,
  bool
  >
  

Adaptor

unary_negate< Predicate > not1( const Predicate& pred );

Interface

Constructor
explicit unary_negate( const Predicate& pred )
Constructs a unary negate object with predicate pred .
()
bool operator()( const argument_type& x ) const
Returns the result of pred ( x )
Example <ospace/osstd/examples/unegate1.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

int array[ 3 ] = { 1, 2, 3 };

class odd : public unary_function< int, bool >
  {
  public:
    odd() {}
    bool operator()( const int& n ) const { return ( n % 2 ) == 1; }
  };

void
main()
  {
  int* p = find_if( array, array + 3, unary_negate< odd >( odd() ) );

  if ( p != array + 3 )
    cout << *p << "\n";
  }

2 is not odd
Example <ospace/osstd/examples/unegate2.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

int array[ 3 ] = { 1, 2, 3 };

class odd : public unary_function< int, bool >
  {
  public:
    odd() {}
    bool operator()( const int& n ) const { return ( n % 2 ) == 1; }
  };

void
main()
  {
  int* p = find_if( array, array + 3, not1( odd() ) );

  if ( p != array + 3 )
    cout << *p << "\n";
  }

2 is not odd

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.