Angelus Mortis
Angelus Mortis

Reputation: 1554

Doesn't ADL considers namespaces associated with template argument?

Consider the simple code :

template<int N> struct foo{};

namespace N
{
    const int a=1;
    void bar(foo<1>& x){}
}

int main()
{
    bar(foo<N::a>());
    return 0;
}

Shouldn't the code work? why it isn't working I wonder. Thanks

Upvotes: 0

Views: 97

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490728

[basic.lookup.argdep]/2:

[ Note: Non-type template arguments do not contribute to the set of associated namespaces.—end note ]

For the code linked in the comments, a typedef in a namespace isn't sufficient either, but for other reasons. The lookup is based on the resolved type, not on the namespace containing the typedef itself (or, equivalently, using).

For example, if you had code like:

namespace A { 
    class T {};
}

namespace B { 
    typedef A::T TT;
}

Using B::TT as an argument would add namespace A to the lookup, but would not add namespace B to the lookup.

Upvotes: 4

Related Questions