bind

template <class Fty, class T1, class T2, ..., class TN>
   unspecified bind(Fty fn, T1 t1, T2 t2, ..., TN tN);
template <class Ret, class Fty, class T1, class T2, ..., class TN>
   unspecified bind(Fty fn, T1 t1, T2 t2, ..., TN tN);

[Added with TR1]

The types Fty, T1, T2, ..., TN must be copy constructible, and INVOKE(fn, t1, ..., tN) must be a valid expression for some values w1, w2, ..., wN.

The first template function returns a forwarding call wrapper g with a weak result type. The effect of g(u1, u2, ..., uM) is INVOKE(f, v1, v2, ..., vN, result_of<Fty cv (V1, V2, ..., VN)>::type), where cv is the cv-qualifiers of g and the values and types of the bound arguments v1, v2, ..., vN are determined as specified below.

The second template function returns a forwarding call wrapper g with a nested type result_type that is a synonym for Ret. The effect of g(u1, u2, ..., uM) is INVOKE(f, v1, v2, ..., vN, Ret), where cv is the cv-qualifiers of g and the values and types of the bound arguments v1, v2, ..., vN are determined as specified below.

The values of the bound arguments v1, v2, ..., vN and their corresponding types V1, V2, ..., VN depend on the type of the corresponding argument ti of type Ti in the call to bind and the cv-qualifiers cv of the call wrapper g as follows:

  • if ti is of type reference_wrapper<T> the argument vi is ti.get() and its type Vi is T&;
  • if the value of std::tr1::is_bind_expression<Ti>::value is true the argument vi is ti(u1, u2, ..., uM) and its type Vi is result_of<Ti cv (U1&, U2&, ..., UN&>::type;
  • if the value j of std::tr1::is_placeholder<Ti>::value is not zero the argument vi is uj and its type Vi is Uj&;
  • otherwise the argument vi is ti and its type Vi is Ti cv &.

For example, given a function f(int, int) the expression bind(f, _1, 0) returns a forwarding call wrapper cw such that cw(x) calls f(x, 0). The expression bind(f, 0, _1) returns a forwarding call wrapper cw such that cw(x) calls f(0, x).

The number of arguments in a call to bind in addition to the argument fn must be equal to the number of arguments that can be passed to the callable object fn. Thus, bind(cos, 1.0) is correct, and both bind(cos) and bind(cos, _1, 0.0) are incorrect.

The number of arguments in the function call to the call wrapper returned by bind must be at least as large as the highest numbered value of is_placeholder<PH>::value for all of the placeholder arguments in the call to bind. Thus, bind(cos, _2)(0.0, 1.0) is correct (and returns cos(1.0)), and bind(cos, _2)(0.0) is incorrect.