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.
#include <functional>
template< class Predicate >
class unary_negate : public unary_function
<
typename Predicate::argument_type,
bool
>
( x )
#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
#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.