如果您不使用参数占位符 (_1
, _2
, ...),然后传递给从返回的函数对象的任何参数std::bind
将被丢弃。和:
std::function<void(int)> f = std::bind(fun, std::placeholders::_1);
正如预期的那样,我得到了一个(又长又难看的)错误。
对于对标准语感兴趣的人:
§20.8.9.1.2 [func.bind.bind]
template<class F, class... BoundArgs>
*unspecified* bind(F&& f, BoundArgs&&... bound_args);
p3 返回:转发调用包装器g
具有弱结果类型(20.8.2)。的效果g(u1, u2, ..., uM)
应该INVOKE(fd, v1, v2, ..., vN, result_of<FD cv (V1, V2, ..., VN)>::type)
, where cv代表cv- 资格赛g
以及绑定参数的值和类型v1, v2, ..., vN
如下指定确定.
p10 绑定参数的值v1, v2, ..., vN
以及它们对应的类型V1, V2, ..., VN
取决于类型TiD
派生自调用bind
和cv-预选赛cv调用包装器的g
如下:
- if
TiD
is reference_wrapper<T>
,参数是tid.get()
及其类型Vi
is T&
;
- 如果值
is_bind_expression<TiD>::value
is true
,参数是tid(std::forward<Uj>(uj)...)
及其类型Vi
is result_of<TiD cv (Uj...)>::type
;
- 如果值
j
of is_placeholder<TiD>::value
不为零,参数为std::forward<Uj>(uj)
及其类型Vi
is Uj&&
;
- 否则,值为
tid
及其类型Vi
is TiD cv &
.