binary_negate, not2


A binary function object that returns the logical negation of executing its binary predicate. With the associated adapter function not2() , you can conveniently construct a binary_negate object directly from a predicate.

Library

Standards<ToolKit>

Declaration


#include <functional>

template< class Predicate >
class binary_negate : public binary_function
  <
  typename Predicate::first_argument_type,
  typename Predicate::second_argument_type,
  bool
  >
  

Adaptor

binary_negate< Predicate > not2( const Predicate& pred );

Interface

Constructor
explicit binary_negate( const Predicate& predicate )
Constructs a binary negate object with predicate predicate .
()
bool operator()( const first_argument_type& x , const second_argument_type& y ) const
Returns the result of predicate ( x , y )
Example <ospace/osstd/examples/bnegate1.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

int array[ 4 ] = { 4, 9, 7, 1 };

void
main()
  {
  sort( array, array+4, binary_negate< greater<int> >( greater<int>() ) );
  for ( int i = 0; i < 4; ++i )
    cout << array[ i ] << "\n";
  }

1
4
7
9
Example <ospace/osstd/examples/bnegate2.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

int array[ 4 ] = { 4, 9, 7, 1 };

void
main()
  {
  sort( array, array + 4, not2( greater< int >() ) );
  for ( int i = 0; i < 4; ++i )
    cout << array[ i ] << "\n";
  }


1
4
7
9

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