How can I make sure that when I sort the data vector, std :: sort will still use the move and move-assign constructor?
Actually, you do not need. You must make sure that the swap function used directly or indirectly uses any trick already used in the move constructor. This I think how it works. In other words, sort needs a good swap, not necessarily a copy.
Where "directly" may simply mean using the default std::swap , which uses the move constructor when possible.
template <class T> void swap (T& a, T& b) { T c(std::move(a)); a=std::move(b); b=std::move(c); }
So, most likely, you do not need to do anything, because swap (or, as @MarcGlisse noted, the sorting algorithm directly) will use the move constructor.
source share