Thursday, 15 August 2013

What is rationale for calling const-copy-ctor in the absence of a move-ctor?

What is rationale for calling const-copy-ctor in the absence of a move-ctor?

I've read, then verified that this the case. But I want to understand:
why this is so
how to know if a call into some library function is NOT doing a move
(other than manually examining the source object after the "move") and
if there is a way (compiler switch or other) to turn off that behavior.
For example, when:
struct A {
A() {...}
A(A &a) {...}
A(A const & A) {...}
};
is constructed as in:
A a1;
A a2 = std::move(a1); //calls const copy (but how would I know?)
results in the const version of the copy ctor being called.

No comments:

Post a Comment