zoukankan      html  css  js  c++  java
  • bind2nd

    bind2nd

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

    返回第二个参数绑定的函数对象

    此函数通过将其第二个参数绑定到固定值x,从二元函数对象op构造一元函数对象。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.
    ";
      return 0;
    }
    
    有3个负面因素。
    

    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 )
  • 相关阅读:
    c语言编程之栈(链表实现)
    c语言编程之队列(链表实现)
    c语言编程之循环队列
    (转)linux下的系统调用函数到内核函数的追踪
    计算机网络
    (转)使用 /proc 文件系统来访问 Linux 内核的内容
    linux驱动之I2C
    (转)Linux 文件系统:procfs, sysfs, debugfs 用法简介
    linux编程之线性表
    linux编程之指针
  • 原文地址:https://www.cnblogs.com/jia0504/p/11379856.html
Copyright © 2011-2022 走看看