You were redirected to cplusplus.com/bind1st || See search results for: "bind1st"
function template
<functional>

std::bind1st

template <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 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:

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.

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

1
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