std::bind
返回的仿函数忽略多余的参数 [ SO1 , SO2 , SO3 ]。一个简单的例子如下所示。
#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
}
很明显,实现 std::bind
这种方式更容易[ SO1a ]。然而,这种对多余论点的忽略是标准化的还是未定义的行为?
最佳答案
是的,对于 std::bind
,多余的参数将被丢弃。
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.
关于c++ - std::bind 是否忽略了符合标准的多余参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68545705/