The rationale for some of the ADL algorithm steps (C++)

情到浓时终转凉″ 提交于 2020-01-14 04:08:31

问题


In short, I am trying to understand the behavior of Argument-Dependent Lookup in C++. Some statements in ISO/IEC 14882:2017 (E) regarding ADL are not clear to me. I hope somebody would clarify them to me.

According to standard,

... Furthermore, if T is a class template specialization, its associated namespaces and classes also include: the namespaces and classes associated with the types of the template arguments provided for template type parameters (excluding template template parameters); the namespaces of which any template template arguments are members; and the classes of which any member templates used as template template arguments are members.

The question is why it has to be a class template specialization? Consider the following example:

#include <iostream>                                                             

using namespace std;                                                            

namespace N                                                                     
{                                                                               
    template <typename T>                                                       
    struct A {};                                                                

    template <typename T>                                                       
    void func (const T&) {cout << __PRETTY_FUNCTION__ << endl;}                 
}                                                                               

template <typename T, template <typename> class S>                              
class X {};                                                                     

int main ()                                                     
{                                                                               
    typedef X<int, N::A> XX;                                                    
    func(XX{});                                                                 
}

As far as I can see, it compiles with both g++ and clang++, and I don't have to define something like

template <>                                                                   
class X<int, N::A> {};

to make it work.

来源:https://stackoverflow.com/questions/59236904/the-rationale-for-some-of-the-adl-algorithm-steps-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!