5

The functor returned by std::bind ignores superfluous arguments [SO1, SO2, SO3]. A simple example looks as follows.

#include <iostream>
#include <functional>

void foo(int a) {
  std::cout << "a=" << a << std::endl;
}

int main() {
  auto f = std::bind(foo, 42);
  f(3141); // a=42
}

It is clear that implementing std::bind in this way is easier [SO1a]. Is, however, this ignoring of superfluous arguments standardized or undefined behavior?

H. Rittich
  • 814
  • 7
  • 15

1 Answers1

4

Yes, for std::bind, the superfluous arguments will be discarded.

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.

songyuanyao
  • 169,198
  • 16
  • 310
  • 405