Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

bind2nd

类模板  <functional>

template <class Operation, class T>
  binder2nd<Operation> bind2nd (const Operation& op, const T& x);

返回第二个参数绑定的函数对象
这个函数通过将二元函数对象op的第二个参数绑定到固定值x来构造一元函数对象。

bind2nd返回的函数对象定义了operator(),它只接受一个参数。 该参数用于调用二元函数对象op,其中x作为第二个参数的固定值。

它的行为定义如下:
template <class Operation, class T>
  binder2nd<Operation> bind2nd (const Operation& op, const T& x)
{
  return binder2nd<Operation>(op, typename Operation::second_argument_type(x));
}
要将第一个参数绑定到一个特定的值,请参见bind1st。

☲  参数


op
派生自binary_function的二元函数对象。

x
op的第二个参数的固定值。

☉  返回值



一元函数对象,等价于op,但第二个参数总是设置为x。
Binder2nd是一个派生自unary_function的类型。

☣  示例



// 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.

🍄  另请参阅



bind1st 返回第一个参数绑定的函数对象(类模板)
binder2nd 生成绑定二个参数的函数对象类(类模板)
unary_function 一元函数对象基类 (类模板)
binary_function 二元函数对象基类 (类模板)

联系我们 免责声明 关于CandCplus 网站地图