function template
<functional>
std::bind2ndtemplate <class Operation, class T> binder2nd<Operation> bind2nd (const Operation& op, const T& x);
Return function object with second parameter bound
This function constructs an unary function object from the binary function object
opby binding its second parameter to the fixed value
x.
The function object returned by bind2nd has its operator() defined such that it takes only one argument. This argument is used to call binary function object op with x as the fixed value for the second argument.
It is defined with the same behavior as:
1
2
3
4
5
template <class Operation, class T>
binder2nd<Operation> bind2nd (const Operation& op, const T& x)
{
return binder2nd<Operation>(op, typename Operation::second_argument_type(x));
}
To bind the first parameter to a specific value, see
bind1st.
ParametersAn unary function object equivalent to
opbut with the second parameter always set to
x.
is a type derived from
unary_function.
Example1
2
3
4
5
6
7
8
9
10
11
12
13
// bind2nd example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main () {
int numbers[] = {10,-20,-30,40,-50};
int cx;
cx = count_if ( numbers, numbers+5, bind2nd(less<int>(),0) );
cout << "There are " << cx << " negative elements.\n";
return 0;
}
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