【发布时间】:2021-05-26 14:03:41
【问题描述】:
在 C++20 中,假设我想要 std::make_unique 一个副本(或酌情移动)并存储一个在转发引用中传递的类似函数的对象...
template<typename F>
std::unique_ptr<???> make_copy_of_functor(F&& f) {
return std::make_unique<???>(std::forward<F>(f));
}
???s 中有什么内容?将F放在那里是否正确...
template<typename F>
std::unique_ptr<F> make_copy_of_functor(F&& f) {
return std::make_unique<F>(std::forward<F>(f));
}
或者我需要以某种方式衰减它吗? (我可能对转发引用的引用折叠规则感到困惑。)
【问题讨论】: