Recently, many questions pop up on how to provide your own swap
function. With C++11, std::swap
will use std::move
and move semantics to swap the given values as fast as possible. This, of course, only works if you provide a move constructor and a move assignment operator (or one that uses pass-by-value).
Now, with that given, is it actually necessary to write your own swap
functions in C++11? I could only think of non-movable types, but then again, the custom swap
s usually work through some kind of "pointer exchange" (aka moving). Maybe with certain reference variables? Hm...
A(const A&) noexcept;
is a typo, or perhaps SO swallowing ampersands? I.e. that you meantA(A&&) noexcept;
(and ditto for the assignment opperator)? Cheers, – Goidelic