要返回std :: move(x)还是不?

Ale*_* C. 12 c++ move-semantics

std::vector<double> foo ()
{
    std::vector<double> t;
    ...

    return t;
}
Run Code Online (Sandbox Code Playgroud)

std::vector<double> foo ()
{
    std::vector<double> t;
    ...

    return std::move (t);
}
Run Code Online (Sandbox Code Playgroud)

相当于?

更确切地说,return x总是相当于return std::move (x)

Ker*_* SB 14

它们不等同,你应该总是使用它return t;.

较长的版本是,当且仅当返回语句符合返回值优化条件时,则返回者绑定到右值引用(或通俗地说," move隐含").

return std::move(t);但是,通过拼写,您实际上会抑制返回值优化!