gpt4 book ai didi

C++ 标准和绑定(bind)函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:44:31 30 4
gpt4 key购买 nike

在 C++ 标准 (N3797) 20.9.9.1.3 中有以下关于 bind 的声明.

Returns: A forwarding call wrapper g with a nested type result_type defined as a synonym for R. The effect of g(u1, u2, ..., uM) shall be INVOKE(fd, std::forward<V1>(v1), std::forward<V2>(v2), ..., std::forward<VN>(vN), R), where the values and types of the bound arguments v1, v2, ..., vN are determined as specified below. The copy constructor and move constructor of the forwarding call wrapper shall throw an exception if and only if the corresponding constructor of FD or of any of the types TiD throws an exception.

但是没有提到未绑定(bind)参数 u1 u2 ... uM在调用包装器中。我错过了什么吗?中间的语句不应该这样读吗?

... The effect of g(u1, u2, ..., uM) shall be INVOKE(fd, std::forward<V1>(v1), std::forward<V2>(v2), ..., std::forward<VN>(vN), std::forward<U1>(u1), ... std::forward<UM>(um), R), where ...

最佳答案

...按以下规定确定:

The values of the bound arguments v1, v2, ..., vN and their corresponding types V1, V2, ..., VN depend on the types TiD derived from the call to bind and the cv -qualifiers cv of the call wrapper g as follows:

  • if TiD is reference_wrapper, the argument is tid.get() and its type Vi is T&;
  • if the value of is_bind_expression::value is true, the argument is tid(std::forward(uj)...) and its type Vi is result_of::type;
  • if the value j of is_placeholder::value is not zero, the argument is std::forward(uj) and its type Vi is Uj&&;
  • otherwise, the value is tid and its type Vi is TiD cv &.

换句话说:

  • 如果您绑定(bind)了一个引用包装器,它会解开包装并将其传递给包装的函数对象
  • 如果您绑定(bind)了 std::bind 的另一个结果,或者 std::is_bind_expression 计算结果为 true 的任何其他结果,它会传递来自调用站点的所有参数并将结果传递给包装的函数对象
  • 如果您绑定(bind)了一个占位符对象,那么它会传入适当的调用站点参数
  • 否则,它传递绑定(bind)参数

关于C++ 标准和绑定(bind)函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23588574/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com