c++ - std::bind 是否忽略了符合标准的多余参数?

标签 c++ c++11

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/

相关文章:

c++ - 在传递给 std::result_of 之前衰减类型

c++ - C 风格使用现代 C++ 类

C++11 在公共(public)函数中设置 lambda

c++ - 以预定义的非均匀概率生成范围内的随机数

c++ - MPI 使用消息标签将值按正确顺序排列

c++ - 检索由 cvApproxPoly() 创建的多边形的点

c++ - 如何在 C++ 中执行二维快速傅里叶变换

c++ - 为什么参数中的默认char*必须是const?

c++ - boost shared_ptr 运算符 =

macos - 使用 Qt 构建时无法使用 C++11 功能