A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/functional/bind2nd/ below:

function template

<functional>

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

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:

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

.

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
1
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
bind1st
Return function object with first parameter bound (function template)
binder2nd
Generate function object class with 2nd parameter bound (class template)
unary_function
Unary function object base class (class template)
binary_function
Binary function object base class (class template)


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