function template
<functional>
std::bind1sttemplate <class Operation, class T> binder1st<Operation> bind1st (const Operation& op, const T& x);
Return function object with first parameter bound
This function constructs an unary function object from the binary function object
opby 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:
1
2
3
4
5
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.
ParametersAn unary function object equivalent to
opbut with the first 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
// 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
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