That is correct behavior.
std::bind
needs this looseness to fit its own specification.
Consider std::placeholders
, which is used to mark parameters that are passed through to the bound function.
using std::placeholders;
std::function<void(int)> f2 = std::bind( F, _1 );
// Parameter 1 is passed to ^^
// the bound function.
f2(7); // The int 7 is passed on to F
Similarly, there is _2
for the second parameter, _3
for the third, and so on.
That brings up an interesting question. How should this function object behave?
auto f3 = std::bind( F, _3 );
As you might imagine, it follows its own promise to pass the third parameter to F. Which means it does nothing to the first two parameters.
f3(10, 20, 30); // The int 30 is passed on to F. The rest? Ignored.
So this is expected behavior, and possibly the only "feature" that std::bind
holds over lambdas, even in C++14 and C++17.
The object produced by std::bind
is designed to accept and ignore any extraneous parameters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…