【发布时间】:2016-09-13 13:31:21
【问题描述】:
std::function 类型擦除构造函数定义为:
template< class F >
function( F f );
赋值运算符定义为:
template< class F >
function& operator=( F&& f );
(源 cppreference)
为什么构造函数通过值获取f,而operator=通过转发引用获取f?
【问题讨论】:
-
但是
std::function有多个构造函数和多个operator=。包括一个对应于move operator=的move构造函数。 -
@michalsrb 在他的例子中
F&&不是 r-value-reference
标签: c++ c++11 std-function perfect-forwarding