class template
<functional>
std::unary_negatetemplate <class Predicate> class unary_negate;
Negate unary function object class
Unary function object class whose call returns the opposite of another unary function, passed to its constructor.Object of type unary_negate are generally constructed using function not1.
The class is defined with the same behavior as:
1
2
3
4
5
6
7
8
9
template <class Predicate> class unary_negate
: public unary_function <typename Predicate::argument_type,bool>
{
protected:
Predicate fn_;
public:
explicit unary_negate (const Predicate& pred) : fn_ (pred) {}
bool operator() (const typename Predicate::argument_type& x) const {return !fn_(x);}
};
1
2
3
4
5
6
7
8
9
10
template <class Predicate> class unary_negate
{
protected:
Predicate fn_;
public:
explicit unary_negate (const Predicate& pred) : fn_ (pred) {}
bool operator() (const typename Predicate::argument_type& x) const {return !fn_(x);}
typedef typename Predicate::argument_type argument_type;
typedef bool result_type;
};
operator()
result_type T Type returned by member operator()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// unary_negate example
#include <iostream> // std::cout
#include <functional> // std::unary_negate
#include <algorithm> // std::count_if
struct IsOdd_class {
bool operator() (const int& x) const {return x%2==1;}
typedef int argument_type;
} IsOdd_object;
int main () {
std::unary_negate<IsOdd_class> IsEven_object (IsOdd_object);
int values[] = {1,2,3,4,5};
int cx;
cx = std::count_if ( values, values+5, IsEven_object );
std::cout << "There are " << cx << " elements with even values.\n";
return 0;
}
There are 2 elements with even values.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4