小编Ard*_*vel的帖子

"使用std :: swap"如何启用ADL?

在什么是复制和交换习语这个例子显示:

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);
}
Run Code Online (Sandbox Code Playgroud)

如何using std::swap启用ADL?ADL只需要一个不合格的名称.我看到的唯一好处using std::swap是,因为std::swap是一个函数模板,你可以在call(swap<int, int>(..))中使用模板参数列表.

如果不是这样的话,那是using std::swap为了什么?

c++ argument-dependent-lookup c++11

14
推荐指数
2
解决办法
3076
查看次数

标签 统计

argument-dependent-lookup ×1

c++ ×1

c++11 ×1