class template
<functional>
std::binder2ndtemplate <class Operation> class binder2nd;
Generate function object class with 2nd parameter bound
Generates an unary function object class from the binary object class
Operationby binding its second parameter to a fixed value.
binder2nd is generally used as a type. The function bind2nd (also defined in header <functional>) can be used to directly construct an object of this type.
binder2nd is constructed using a binary function object as argument. A copy of this object is used by its member operator() to generate a result from its parameter and the fixed value set on construction.
This class is derived from unary_function and is typically defined as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
template <class Operation> class binder2nd
: public unary_function <typename Operation::first_argument_type,
typename Operation::result_type>
{
protected:
Operation op;
typename Operation::second_argument_type value;
public:
binder2nd ( const Operation& x,
const typename Operation::second_argument_type& y) : op (x), value(y) {}
typename Operation::result_type
operator() (const typename Operation::first_argument_type& x) const
{ return op(x,value); }
};
class is specifically designed to bind function objects (
operations) derived from
binary_function(it requires member
first_argument_typeand
second_argument_type).
Members1
2
3
4
5
6
7
8
9
10
11
12
13
14
// binder2nd example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main () {
binder2nd < less<int> > IsNegative (less<int>(),0);
int numbers[] = {10,-20,-30,40,-50};
int cx;
cx = count_if (numbers,numbers+5,IsNegative);
cout << "There are " << cx << " negative elements.\n";
return 0;
}
Output:
There are 3 negative elements.See also
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