On Wednesday, 22 October 2014 at 19:44:49 UTC, Jonathan M Davis
wrote:
The only exception would be if the compiler determines that the
lvalue in question is never used after that call, in which
case, it might just move the object rather than copy it.
There's an additional restriction: local variables are guaranteed
to live until the end of the scope they are declared in, and they
will be destroyed in inverse order of declaration. A move can
only happen if this guarantee wouldn't be violated. This is the
case, for example, if the object doesn't have a destructor. If it
does have one, it can still be moved if the call is at the end of
the variable's scope, and the relative order of destruction of
the other variables is unchanged. (The variable would then be
destroyed on return inside the function, in an order depending on
its position in the argument list.)
So, you mean if draw was a member function of Bezier, and you
did something like
Bezier(100, 100, 133, 200, 166, 200, 200, 200).draw()
you want to know whether a copy of the Bezier object would be
made? The this member of a struct is a ref - in this case ref
Bezier - so it doesn't make a copy. The object would be
constructed in place and then be destroyed after it's used
(though exactly when it would be destroyed if the object were
created and called in a complex expression, I'm not sure -
possibly as soon as the function call terminated, possibly when
the statement completed).
AFAIK, always at the end of the entire statement, but I don't
know about the order.