I'm implementing a class with a similar interface to std::array
, which has both the member swap()
and the non-member swap()
.
Since I want my class to mimic the standard containers, I would like to implement both kinds of swap()
(the non-member swap()
is implemented via ADL, since specializing std::swap()
isn't permitted):
class A {
public:
friend void swap(A& a, A& b) { /* swap the stuff */ }
void swap(A& other) { swap(*this, other); }
};
However, it seems like I can't call the non-member swap()
from inside the class, because it prefers the member swap()
even though it only has a single parameter. Changing it to ::swap(*this, other)
doesn't work as well, because the in-class friend function is only findable via ADL. How might I call the non-member swap()
from inside the class?