【发布时间】:2015-03-23 17:13:50
【问题描述】:
在What is the copy-and-swap idiom 中显示了这个例子:
friend void swap(dumb_array& first, dumb_array& second) // nothrow
{
// enable ADL (not necessary in our case, but good practice)
using std::swap;
// by swapping the members of two classes,
// the two classes are effectively swapped
swap(first.mSize, second.mSize);
swap(first.mArray, second.mArray);
}
using std::swap 究竟是如何启用 ADL 的? ADL 只需要一个非限定名称。我看到 using std::swap 的唯一好处是,由于 std::swap 是一个函数模板,您可以在调用中使用模板参数列表 (swap<int, int>(..))。
如果不是这样,那么using std::swap 是干什么用的?
【问题讨论】:
标签: c++ c++11 argument-dependent-lookup