The swap in the last line compiles, because the signature in boost::swap accepts references to const. I am not sure what happens next, but this is probably an infinite recursion.
Note that std::swap does not have this problem, because it is constrained (T shall be move constructible and move assignable).
Consider the following code. This reproduces the situation from
boost::optional
(see issue #63) which relies onboost::swap
.The
swap
in the last line compiles, because the signature inboost::swap
accepts references to const. I am not sure what happens next, but this is probably an infinite recursion.Note that
std::swap
does not have this problem, because it is constrained (T shall be move constructible and move assignable).