When using std::swap with user-defined types, we need to be careful with the consequences of Argument Dependent Lookup.
To properly call std::swap, we have to pull the default implementation into the local scope before making an unqualified call.
Alternatively, with C++20, a qualified call to std::ranges::swap will always do the correct thing.
Compiler Explorer link: https://compiler-explorer.com/z/4nY1sK3Kn
@simontoth Is there a neat trick to implement a custom swap function for my class in terms of a memberwise swap? Basically what "=default" does for operator==?
@asperamanca Sadly no, but if you only have swappable members, the default three-move swap should be generally optimal.
@simontoth I was confused recently when I found that std::ranges::swap is not std::ranges::swap_ranges when my code didn't compile.
Kind of weird that it is placed in a 'ranges' namespace.