0

Possible Duplicate:
Using std::move() when returning a value from a function to avoid to copy

Assume you have any sort of variable inside a function and you want to return it:

X foo(/*...*/) {
  X x;
  //...
  return x;
}

I'm trying to determine if there is any case where return std::move(x); would be problematic. Clearly x will go out of scope, so there doesn't seem to be a good reason to keep it around. However, I'm not sure what the effects would be if X was some Y& referencing some long(er) lived variable.

Community
  • 1
  • 1
bitmask
  • 32,434
  • 14
  • 99
  • 159

0 Answers0