我正在实现一个具有与std::array
相似的接口的类,该类同时具有member swap()
和swap()
。
由于我想让我的班级模仿标准容器,所以我想实现两种non-member swap()
(非成员swap()
是通过ADL实现的,因为不允许专门使用swap()
:]]]
swap()
但是,似乎我无法从类内部调用非成员
std::swap()
,因为即使它只有一个参数,它也更喜欢成员class A { public: friend void swap(A& a, A& b) { /* swap the stuff */ } void swap(A& other) { swap(*this, other); } };
。将其更改为swap()
也不起作用,因为只能通过ADL找到类中的好友函数。我怎么能从班级内部调用非成员swap()
?
我正在实现一个具有与std :: array类似的接口的类,该类同时具有成员swap()和非成员swap()。因为我希望我的班级模仿标准容器,所以我想...
以下对我有用(它打印两次)