Binder Classes
Utilities » Function Objects
Collaboration diagram for Binder Classes:

## Namespaces

namespace | std::placeholders

## Classes

struct | std::_Placeholder< _Num >
class | std::binder1st< _Operation >
class | std::binder2nd< _Operation >
struct | std::is_bind_expression< _Tp >
struct | std::is_bind_expression< _Bind< _Signature > >
struct | std::is_bind_expression< _Bind_result< _Result, _Signature > >
struct | std::is_bind_expression< const _Bind< _Signature > >
struct | std::is_bind_expression< const _Bind_result< _Result, _Signature > >
struct | std::is_bind_expression< const volatile _Bind< _Signature > >
struct | std::is_bind_expression< const volatile _Bind_result< _Result, _Signature > >
struct | std::is_bind_expression< volatile _Bind< _Signature > >
struct | std::is_bind_expression< volatile _Bind_result< _Result, _Signature > >
struct | std::is_placeholder< _Tp >
struct | std::is_placeholder< _Placeholder< _Num > >

## Functions

template<typename _Result, typename _Func, typename... _BoundArgs>
constexpr _Bindres_helper< _Result, _Func, _BoundArgs... >::type | std::bind (_Func &&__f, _BoundArgs &&... __args)
template<typename _Func, typename... _BoundArgs>
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type | std::bind (_Func &&__f, _BoundArgs &&... __args)
template<typename _Operation, typename _Tp>
binder1st< _Operation > | std::bind1st (const _Operation &__fn, const _Tp &__x)
template<typename _Operation, typename _Tp>
binder2nd< _Operation > | std::bind2nd (const _Operation &__fn, const _Tp &__x)

## Detailed Description

Binders turn functions/functors with two arguments into functors with a single argument, storing an argument to be applied later. For example, a variable `B` of type `binder1st` is constructed from a functor `f` and an argument `x`. Later, B's `operator()` is called with a single argument `y`. The return value is the value of `f(x,y)`. `B` can be called with various arguments (y1, y2, ...) and will in turn call `f(x,y1)`, `f(x,y2)`, ...

The function `bind1st` is provided to save some typing. It takes the function and an argument as parameters, and returns an instance of `binder1st`.

The type `binder2nd` and its creator function `bind2nd` do the same thing, but the stored argument is passed as the second parameter instead of the first, e.g., `bind2nd`(std::minus<float>(),1.3) will create a functor whose `operator()` accepts a floating-point number, subtracts 1.3 from it, and returns the result. (If `bind1st` had been used, the functor would perform 1.3 - x instead.

Creator-wrapper functions like `bind1st` are intended to be used in calling algorithms. Their return values will be temporary objects. (The goal is to not require you to type names like `std::binder1st<std::plus<int>>` for declaring a variable to hold the return value from `bind1st(std::plus<int>(),5)`.

These become more useful when combined with the composition functions.

These functions are deprecated in C++11 and can be replaced by `std::bind` (or `std::tr1::bind`) which is more powerful and flexible, supporting functions with any number of arguments. Uses of `bind1st` can be replaced by `std::bind(f, x, std::placeholders::_1)` and `bind2nd` by `std::bind(f, std::placeholders::_1, x)`.

## Function Documentation

## bind() [1/2]

template<typename _Result, typename _Func, typename... _BoundArgs>

_Bindres_helper< _Result, _Func, _BoundArgs... >::type std::bind | ( | _Func && | __f,
|  | _BoundArgs &&... | __args )

inline constexpr

Function template for std::bind<R>.

Since
  C++11

Definition at line 895 of file functional.

References forward().

## bind() [2/2]

template<typename _Func, typename... _BoundArgs>

_Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type std::bind | ( | _Func && | __f,
|  | _BoundArgs &&... | __args )

inline constexpr

Function template for std::bind.

Since
  C++11

Definition at line 870 of file functional.

References forward().

## bind1st()

template<typename _Operation, typename _Tp>

binder1st< _Operation > std::bind1st | ( | const _Operation & | __fn,
|  | const _Tp & | __x )

inline

One of the binder functors.

Definition at line 136 of file binders.h.

References bind1st().

Referenced by bind1st().

## bind2nd()

template<typename _Operation, typename _Tp>

binder2nd< _Operation > std::bind2nd | ( | const _Operation & | __fn,
|  | const _Tp & | __x )

inline

One of the binder functors.

Definition at line 172 of file binders.h.

References bind2nd().

Referenced by bind2nd().