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

std::

bind1st

类模板  <functional>

template <class Operation, class T>
  binder1st<Operation> bind1st (const Operation& op, const T& x);

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

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

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

☲  参数


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

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

☉  返回值



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

☣  示例



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

🍄  另请参阅



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

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