C++ c++;在函数中使用语句,后跟函数名(用于ADL?)

C++ c++;在函数中使用语句,后跟函数名(用于ADL?),c++,swap,C++,Swap,在这个问题中,在最上面的答案中,在实现swap public friend重载的部分中,实现使用了以下内容: friend void swap(dumb_array& first, dumb_array& second){ //the line of code below using std::swap; //then it calls the std::swap function on data members of the dumb_array`s }

在这个问题中,在最上面的答案中,在实现swap public friend重载的部分中,实现使用了以下内容:

friend void swap(dumb_array& first, dumb_array& second){
    //the line of code below
    using std::swap;
    //then it calls the std::swap function on data members of the dumb_array`s
}

我的问题如下:这里使用的
使用std::swap
是什么(答案提到了与启用ADL相关的内容);此处具体调用了“using”的哪个用例,添加该行代码和不添加该行代码的效果如何?

using语句使该行工作:

swap(first, second);
请注意,我们可以省略
swap
前面的
std::

重要的是,
std::swap(…)
是一个合格的查找,但是
swap(…)
是一个不合格的查找。主要区别在于,限定查找是在特定的名称空间或范围(指定的名称空间或范围)中调用函数,而非限定查找更灵活,因为它将查看当前上下文的父范围以及全局名称空间。此外,非限定查找还将查看参数类型的范围。这是一个不错的工具,但也很危险,因为它可以从意外的地方调用函数

ADL只能用于非限定查找,因为它必须搜索其他名称空间和作用域

使用std::swap
还可以确保,如果通过ADL找不到函数,默认情况下它将调用
std::swap

此习惯用法允许用户定义交换函数:

struct MyType {
    // Function found only through ADL
    friend void swap(MyType& l, MyType& r) {
        // ...
    }
};

如果你能简单地解释一下不合格查找和合格查找之间的区别,我很乐意接受你的回答