Reputation: 1103
Please, explain, why in the following code there is no error:
void f()
{
}
void h()
{
std::bind(f)(42);
}
Why compiler doesn't complain about redundant parameter in std::bind while binding function f? And if it shouldn't, please explain why this can be useful.
Upvotes: 2
Views: 200
Reputation: 40603
This code is conformant. The arguments that you pass to the result of bind are only used if needed.
Using the terminology from the standard: u
is the result of std::bind(f, t1, ..., tN)
.
Approximately speaking:
When u(u1, u2, ..., uM)
is called, f
is called as f(v1, ..., vN)
, where the values of vi
are determined by the following algorithm:
//N is the N from `std::bind(f, t1, ..., tN)`
For each i in 1 to N:
if (ti is a reference wrapper) vi is the unwrapped version of t1
if (ti is a bind_expression) vi is the result of calling ti with u1, ..., uM
if (ti is a placeholder) vi is uj (where j is is_placeholder<decltype(ti)>::value)
otherwise vi is ti
Upvotes: 2