.
, s1, ( no-op int ). , , .
New objects in s1 will be copied from those in s2, which can take considerable time. If you do not want to save s2 after the assignment, it is better to use swap for two containers or use the C ++ 11 move destination.
std::swap(s1, s2);
s1 = std::move(s2);
Both of them, most likely, will simply change one pointer, leaving the contents that you want to save in s1, and the rest in s2, which will be cleared when s2 is out of scope.
source
share