Should you overload swap in the std namespace?(你应该在 std 命名空间中重载交换吗?)
问题描述
我今天读到一些有趣的东西,它说在用户提供的类型(作为模板参数提供)上调用交换的标准"方法是......
使用 std::swap;交换(东西,其他东西);
这样做的原因是使用参数依赖查找来使用用户命名空间中的 swap
函数或 std
中的 swap
> 命名空间.这对我提出了一个有趣的问题.当我为我的一个类重载 std::swap
时,我实际上是在 std
命名空间中定义它... namespace std { void swap(/*...*/){/*...*