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 )
  • 相关阅读:
    python-通过psutil监控系统性能
    集合类和JAVA多线程
    JAVA异常和基础类库
    类设计基础与进阶
    面对对象思想
    AtCoder Beginner Contest 185
    Java概述
    友链
    牛客编程巅峰赛S2第7场
    牛客小白月赛30
  • 原文地址:https://www.cnblogs.com/jia0504/p/11379856.html
Copyright © 2011-2022 走看看