Kiedy należy użyć std :: move w wartości zwracanej przez funkcję? [duplikować]

To pytanie ma już tutaj odpowiedź:

c ++ 11 Optymalizacja wartości zwrotu lub przeniesienie? [duplikować] 4 odpowiedzi

W tym przypadku

struct Foo {};
Foo meh() {
  return std::move(Foo());
}

Jestem pewien, że ruch jest niepotrzebny, ponieważ nowo utworzonyFoo będzie wartością x.

Ale co w takich przypadkach?

struct Foo {};
Foo meh() {
  Foo foo;
  //do something, but knowing that foo can safely be disposed of
  //but does the compiler necessarily know it?
  //we may have references/pointers to foo. how could the compiler know?
  return std::move(foo); //so here the move is needed, right?
}

Myślę, że ruch jest potrzebny?

questionAnswers(6)

yourAnswerToTheQuestion