Can std :: move () or its explicit equivalent of a local variable resolve elision?

For instance:

Big create()
{
    Big x;
    return std::move(x);
//  return static_cast<typename std::remove_reference<T>::type&&>(t) // why not elide here?
}

Assuming that applying std::move()to return a local variable prohibits movement-semantics, because compilers cannot make any assumptions about the internal functions of functions in general, with regard to cases where these assumptions are not needed, for example, when:

  • std::move(x) built-in (possibly always)
  • std::move(x) is written as: static_cast<typename std::remove_reference<T>::type&&>(t)

In accordance with the current standard, implementations are allowed to apply NRVO ...

- return , - ( , - (18.3)) ( cv-qualification) , /

, 1), 2) . , std::move() , ?

+4
2

-. " std::move() (N) RVO '

, , .

return , - ( , - (18.3)) ( cv-qualification)

NRVO , , std::move(), , std::move X, X&&. !

+2

, " ". , , , " ". , , , , . , , , , .

, ? , , (, , ), , . , , (, string), , , , ( ) ( , , ).

, , . , . , . , , , , , .

: , ? . , , .

+2

Source: https://habr.com/ru/post/1683189/


All Articles