问题
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