| bind2nd |
function template |
template <class Operation, class T>
binder2nd<Operation> bind2nd (const Operation& op, const T& x); |
<functional> |
Return function object with second parameter binded
This function constructs an unary function object from the binary function object op by 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:
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.
Parameters
- op
- Binary function object derived from binary_function.
- x
- Fixed value for the second parameter of op.
Return value
An unary function object equivalent to
op but with the second parameter always set to
x.
binder2nd is a type derived from
unary_function.
Example
// 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
| bind1st | Return function object with first parameter binded (function template) |
| binder2nd | Generate function object class with 2nd parameter binded (class template) |