Question

In the C++ standard (N3797) 20.9.9.1.3 has the following statements about bind.

Returns: A forwarding call wrapper g with a nested type result_type defined as a synonym for R. The effect of g(u1, u2, ..., uM) shall be INVOKE(fd, std::forward<V1>(v1), std::forward<V2>(v2), ..., std::forward<VN>(vN), R), where the values and types of the bound arguments v1, v2, ..., vN are determined as specified below. The copy constructor and move constructor of the forwarding call wrapper shall throw an exception if and only if the corresponding constructor of FD or of any of the types TiD throws an exception.

But there's no mention of the unbound arguments u1 u2 ... uM in the call wrapper. Am I missing something? Shouldn't the statement in the middle read as follows?

... The effect of g(u1, u2, ..., uM) shall be INVOKE(fd, std::forward<V1>(v1), std::forward<V2>(v2), ..., std::forward<VN>(vN), std::forward<U1>(u1), ... std::forward<UM>(um), R), where ...

Was it helpful?

Solution

... are determined as specified below:

The values of the bound arguments v1, v2, ..., vN and their corresponding types V1, V2, ..., VN depend on the types TiD derived from the call to bind and the cv -qualifiers cv of the call wrapper g as follows:

  • if TiD is reference_wrapper, the argument is tid.get() and its type Vi is T&;
  • if the value of is_bind_expression::value is true, the argument is tid(std::forward(uj)...) and its type Vi is result_of::type;
  • if the value j of is_placeholder::value is not zero, the argument is std::forward(uj) and its type Vi is Uj&&;
  • otherwise, the value is tid and its type Vi is TiD cv &.

In other words:

  • If you bound a reference wrapper, it unwraps that and passes it into the wrapped function object
  • If you bound another result of std::bind, or anything else which std::is_bind_expression evaluates as true, it passes all of the arguments from the call site to that and passes the result to the wrapped function object
  • If you bound a placeholder object, then it passes in the appropriate call site argument
  • Otherwise, it passes the bound argument
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top