ADL 不考虑与模板参数关联的命名空间吗?
Doesn't ADL considers namespaces associated with template argument?
考虑简单的代码:
template<int N> struct foo{};
namespace N
{
const int a=1;
void bar(foo<1>& x){}
}
int main()
{
bar(foo<N::a>());
return 0;
}
代码不应该工作吗?我想知道为什么它不起作用。谢谢
[basic.lookup.argdep]/2:
[ Note: Non-type template arguments do not contribute to the set of associated namespaces.—end note ]
对于评论中链接的代码,命名空间中的 typedef 也不够,但出于其他原因。查找基于已解析的类型,而不是基于包含 typedef
本身(或等效地,using
)的名称空间。
例如,如果您有如下代码:
namespace A {
class T {};
}
namespace B {
typedef A::T TT;
}
使用 B::TT
作为参数会将 namespace A
添加到查找中,但不会将 namespace B
添加到查找中。
考虑简单的代码:
template<int N> struct foo{};
namespace N
{
const int a=1;
void bar(foo<1>& x){}
}
int main()
{
bar(foo<N::a>());
return 0;
}
代码不应该工作吗?我想知道为什么它不起作用。谢谢
[basic.lookup.argdep]/2:
[ Note: Non-type template arguments do not contribute to the set of associated namespaces.—end note ]
对于评论中链接的代码,命名空间中的 typedef 也不够,但出于其他原因。查找基于已解析的类型,而不是基于包含 typedef
本身(或等效地,using
)的名称空间。
例如,如果您有如下代码:
namespace A {
class T {};
}
namespace B {
typedef A::T TT;
}
使用 B::TT
作为参数会将 namespace A
添加到查找中,但不会将 namespace B
添加到查找中。