如何理解这些方式可以消除对显式 std::move 的大部分需求?任何人都可以通过一些简单的例子说清楚吗?

How to comprephend these ways could eliminate most need for explicit std::move? Could anybody make it clear by some simple examples?

如何理解这些方法(包括不要使变量的范围不必要地变大,编写 return 值的短函数,returning 局部变量)可以消除对显式 std::move?

任何人都可以通过一些简单的例子说清楚吗?我是 C++ 的新手。对于这个问题的任何提示,我将不胜感激。 为了您的方便,我post下面的所有引号。

Moving is done implicitly when the source is an rvalue (e.g., value in a return treatment or a function result), so don’t pointlessly complicate code in those cases by writing move explicitly. Instead, write short functions that return values, and both the function’s return and the caller’s accepting of the return will be optimized naturally. In general, following the guidelines in this document (including not making variables’ scopes needlessly large, writing short functions that return values, returning local variables) help eliminate most need for explicit std::move.

通过创建子函数,您可能会改变

void consume(std::vector<int>&&);

void foo()
{
    std::vector<int> v;
    for (int i = 0; i != 10; ++i) {
        v.push_back(i);
    }
    consume(std::move(v));
}

来自

void consume(std::vector<int>&&);

std::vector<int> make_vector()
{
    std::vector<int> v;

    for (int i = 0; i != 10; ++i) {
        v.push_back(i);
    }
    return v; // implicit move. or NRVO
}
void foo()
{
    consume(make_vector()); // no explicit move needed.
}

这样也可以更好地阅读。