In the following situation can a compiler automatically move the function argument v or does it have to be declared manually?
std::vector Filter(std::vector v);
void DoSomeStuffAndCallFilter(std::vector v)
{
// do some stuff to v
// can the compiler automatically std::move v in this call?
// ie. return Filter(std::move(v));
//
return Filter(v);
}
In your case, the compiler can do so as an allowed optimisation under the as-if rule, because it knows the destructor and copy-constructor of your std::vector
intimately, and can thus prove there is no difference to the observable behavior.
Still, it is a "quality of implementation issue", and depends on heavy optimisations being done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With