Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

bind1st(), bind2nd(), binder1st, binder2nd

Library:  General utilities


Local Index

No Entries


Templatized utilities to bind values to function objects


#include <functional>

namespace std {
  template <class Operation>
  class binder1st;
  template <class Operation, class T>
  binder1st<Operation> bind1st(const Operation&, const T&);

  template <class Operation>
  class binder2nd ;

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


Because so many functions included in the C++ Standard Library take other functions as arguments, the library includes classes that let you build new function objects out of old ones. Both bind1st() and bind2nd() are functions that take as arguments a binary function object f and a value x, and return, respectively, classes binder1st and binder2nd. The underlying function object must be a subclass of binary_function.

Class binder1st binds the value to the first argument of the binary function, and binder2nd does the same thing for the second argument of the function. The resulting classes can be used in place of a unary predicate in other function calls.

For example, you could use the count_if() algorithm to count all elements in a vector that are less than 7, using the following:

The function counts the number of elements in the range [v.begin(), v.end()) as denoted by the first two iterator arguments that satisfy the predicate specified by the third argument and returns the result.



See Also

Function Objects

Standards Conformance


Previous fileTop of DocumentContentsIndex pageNext file