What is the behaviour of compiler generated move constructor?

does std::is_move_constructible<T>::value == true implies that T has a usable move constructor?

Either a move constructor or a copy constructor. Remember that the operation of copy construction satisfies all the requirements that are placed upon the operation move construction, and some more.

In Standard terms, a MoveConstructible object is one for which the evaluation of the expression:

T u = rv; 

makes u equivalent to the value of rv before the construction; the state of rv after being moved-from is unspecified. But since it is unspecified, this means the state could even be identical to the one rv had before being moved from: In other words, u could be a copy of rv.

In fact, the Standard defines the CopyConstructible concept to be a refinement of the MoveConstructible concept (so everything which is CopyConstructible is also MoveConstructible, but not vice versa).

if so, what is the default behaviour of it?

The behavior of an implicitly generated move constructor is to perform a member-wise move of the data members of the type for which it is generated.

Per Parahgraph 12.8/15 of the C++11 Standard:

The implicitly-defined copy/move constructor for a non-union class X performs a memberwise copy/move
of its bases and members
. [ Note: brace-or-equal-initializers of non-static data members are ignored. See
also the example in 12.6.2. —end note ]

Moreover:

1 – is f2 move constructed ?

Yes.

2 – if so, shouldn’t the rvalue be invalidated?

Moving a pointer is the same as copying it. So no invalidation is going on, neither should it be going on. If you want a move constructor that leaves the moved-from object in a particular state (i.e. sets a pointer data member to nullptr), you have to write your own – or delegate this responsibility to some smart pointer class such as std::unique_ptr.

Notice, that the word “invalidated” is not quite correct here. Move constructors (as well as move assignment operators) are meant to leave the moved-from object in a valid (yet unspecified) state.

In other words, the class invariant needs to be respected – and it should be possible to invoke on a moved-from objects operations that do not have any precondition on its state (usually, destruction and assignment).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)