在以下代碼段中是否需要std::move
?在這裏需要`std :: move`嗎?
std::function<void(int)> my_std_function;
void call(std::function<void(int)>&& other_function)
{
my_std_function.swap(std::move(other_function));
}
據我所知call()
接受右值引用..但因爲右值引用本身就是一個左值,以調用swap(std::function<void(int)>&&)
我已經與std::move
我的推理是否正確或在這種情況下可以省略std::move
(並且如果可以,爲什麼?)
好像你想發出operator =而不是swap在這裏。然後,是的,使用移動。 –