bind2nd [C++ Reference]
Keywords: stl,functional,bind2nd
Date: 2010-01-25T14:46:42-0800

[[bind2nd]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## bind2nd

Syntax:

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

bind the second argument of the binary function.

For example:

    #include <iostream>
    using std::cout;
    using std::endl;
    using std::boolalpha;
    #include <algorithm>
    using std::transform;
    #include <functional>
    using std::bind2nd;
    using std::less;

    int main(int argc, char **argv) {
      int a1[]= {0,1,2,3,4,5};
      const size_t SIZE= sizeof(a1) / sizeof(*a1);
      bool is_less[SIZE] = {false};
      transform(a1, a1+SIZE, is_less, bind2nd(less<int>(), 3));
      for(size_t i=0; i<SIZE; i++){
        cout << a1[i] << " < 3 :"<< boolalpha << is_less[i] << endl;;
      }
      return EXIT_SUCCESS;
    }

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •