【发布时间】:2016-01-24 14:29:14
【问题描述】:
根据cppreference,std::function有以下三个构造函数重载:
template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc,
const function& other );
template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc,
function&& other );
template< class F, class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, F f );
只留下最后一个不就足够了吗?前两个会提供更好的性能吗(无论如何,它们更专业)?如果可以,怎么办?
【问题讨论】:
-
第三个版本至少得把
f作为转发参考。 -
@nwp 同意。但在标准中是这样规定的。一定是有原因的。
标签: c++ constructor language-lawyer c++14 std-function