Saturday, 10 August 2013

How to properly define a move constructor?

How to properly define a move constructor?

I did search the internet and found 3 ways of defining a move constructor:
Relying on compiler:
T(T&& other) = default;
Dereference this pointer:
T(T&& other) {
*this = std::move(other);
}
Explicitly reassign all members:
T(T&& other) {
T.a = other.a;
T.b = other.b;
//...
}
Which one is the proper way ? (And is the second one even correct?)

No comments:

Post a Comment