When should I use forward and move?

后端 未结 4 1802
长情又很酷
长情又很酷 2021-02-05 12:07

I have a code that operates on a vector:

template
void doVector(vector& v, T&& value) {
    //....
    v.push_back(value);         


        
4条回答
  •  野的像风
    2021-02-05 12:32

    http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Scott-Meyers-Universal-References-in-Cpp11

    That video, IMO, has the best explanation of when to use std::forward and when to use std::move. It presents the idea of a Universal Reference which is IMO an extremely useful tool for reasoning about move semantics.

提交回复
热议问题