class template
<functional>
std::binary_negatetemplate <class Predicate> class binary_negate;
Negate binary function object class
Binary function object class whose call returns the opposite of another binary function, passed to its constructor.Object of type binary_negate are generally constructed using function not2.
The class is defined with the same behavior as:
1
2
3
4
5
6
7
8
9
10
11
12
template <class Predicate> class binary_negate
: public binary_function <typename Predicate::first_argument_type,
typename Predicate::second_argument_type, bool>
{
protected:
Predicate fn_;
public:
explicit binary_negate ( const Predicate& pred ) : fn_ (pred) {}
bool operator() (const typename Predicate::first_argument_type& x,
const typename Predicate::second_argument_type& y) const
{ return !fn_(x,y); }
};
1
2
3
4
5
6
7
8
9
10
11
template <class Predicate> class binary_negate
{
protected:
Predicate fn_;
public:
explicit binary_negate (const Predicate& pred) : fn_ (pred) {}
bool operator() (const typename Predicate::argument_type& x) const {return !fn_(x,y);}
typedef typename Predicate::first_argument_type first_argument_type;
typedef typename Predicate::second_argument_type second_argument_type;
typedef bool result_type;
};
operator()
second_argument_type T Type of the second argument in member 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
// binary_negate example
#include <iostream> // std::cout
#include <functional> // std::binary_negate, std::equal_to
#include <algorithm> // std::mismatch
#include <utility> // std::pair
int main () {
std::equal_to<int> equality;
std::binary_negate < std::equal_to<int> > nonequality (equality);
int foo[] = {10,20,30,40,50};
int bar[] = {0,15,30,45,60};
std::pair<int*,int*> firstmatch,firstmismatch;
firstmismatch = std::mismatch (foo,foo+5,bar,equality);
firstmatch = std::mismatch (foo,foo+5,bar,nonequality);
std::cout << "First mismatch in bar is " << *firstmismatch.second << "\n";
std::cout << "First match in bar is " << *firstmatch.second << "\n";
return 0;
}
First mismatch in bar is 0 First match in bar is 30
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