| bind1st |
function template |
template <class Operation, class T>
binder1st<Operation> bind1st (const Operation& op, const T& x); |
<functional> |
Return function object with first parameter binded
This function constructs an unary function object from the binary function object op by binding its first parameter to the fixed value x.
The function object returned by bind1st 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 first argument.
It is defined with the same behavior as:
template <class Operation, class T>
binder1st<Operation> bind1st (const Operation& op, const T& x)
{
return binder1st<Operation>(op, typename Operation::first_argument_type(x));
} |
To bind the second parameter to a specific value, see bind2nd.
Parameters
- op
- Binary function object derived from binary_function.
- x
- Fixed value for the first parameter of op.
Return value
An unary function object equivalent to
op but with the first parameter always set to
x.
binder1st is a type derived from
unary_function.
Example
// bind1st example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main () {
int numbers[] = {10,20,30,40,50,10};
int cx;
cx = count_if (numbers, numbers+6, bind1st(equal_to<int>(),10) );
cout << "There are " << cx << " elements that are equal to 10.\n";
return 0;
} |
There are 2 elements that are equal to 10.
|
See also
| bind2nd | Return function object with second parameter binded (function template) |
| binder1st | Generate function object class with 1st parameter binded (class template) |