After dealing with some weird stuff yesterday, the cause of my error was that std::bind
can take more arguments than it needs to make the call
int f(int);
auto b = std::bind(f);
b(1,2,3,4,5,6); // 2-6 are discarded
cppreference claims:
If some of the arguments that are supplied in the call to g() are not matched by any placeholders stored in g, the unused arguments are evaluated and discarded.
Searching through the standard I don't see anything that supports this. The only thing that possibly makes this okay is:
20.9.2/4 A forwarding call wrapper is a call wrapper that can be called with an arbitrary argument list and delivers the arguments to the wrapped callable object as references
because, (I suppose) it doesn't say "delivers all the arguments" but I'm unconvinced.
My "Why" in this question consists of two parts
What reading of the standard makes it clear that
std::bind
is allowed to discard arguments?Why is this desirable behavior? It feels very not-c++ to me. I can't think of a non-contrived situation where I'd want this, but can think of times it would be a problem. Does it somehow make the implementation easier in a way I'm not seeing?