Let's suppose that I have struct Foo
with move constructor
and operator=(Foo&&)
, and I used it as data member:
Foo f()
{
Foo foo;
//code
return foo;
}
struct Boo {
Foo foo;
Boo() {
foo = f();//1
foo = std::move(f());//2
}
};
In case (2) I actually not need std::move
,
but what if I used it here, does this make something bad,
like preventing optimization?
I read this: Why does std::move prevent RVO?
and find out that changing return foo;
to return std::move(foo);
cause disabling of RVO
, but what about (2) does it cause the similar situation? And if so, why?