M
m0shbear
Suppose I have a container type C<T>, which implements
MoveConstructable, MoveAssignable, and member function swap(C<T>&).
In which case is it more elegant to use
C<T> c1;
// fill c1 with data
C<T> c2 = std::move(c1);
over
C<T> c1;
// fill c1 with data
C<T> c2;
c2.swap(c1);
?
Granted, the .swap technique was a hack for moving containers in pre-C+
+11 classes, but now that C++11 is out, does it have any merit for new
classes?
MoveConstructable, MoveAssignable, and member function swap(C<T>&).
In which case is it more elegant to use
C<T> c1;
// fill c1 with data
C<T> c2 = std::move(c1);
over
C<T> c1;
// fill c1 with data
C<T> c2;
c2.swap(c1);
?
Granted, the .swap technique was a hack for moving containers in pre-C+
+11 classes, but now that C++11 is out, does it have any merit for new
classes?