可以采用通过ADL发现的函数的地址吗? 例如: template<class T>
void (*get_swap())(T &, T &)
{
return & _________; // how do I take the address of T's swap() function?
}
int main()
{
typedef some_type T;
请考虑以下代码,其中f的重载位置会导致一些非直观的行为。代码在Clang 3.4.1和gcc 4.8中都没有警告。 template<typename T>
struct A
{
static const int value = sizeof(f(T()));
};
struct B
{
};
struct D : B
{
};
char f(B);
//
C++具有ADL(参数相关查找),正如其名称所描述的那样,函数的上下文(名称空间)可以从参数(的任何一个)的上下文(名称空间)隐含。 fun(a); // if the type of a is in namespace ns deduce ns::f if available
我的问题是,如果反过来也有可能通过某种技术?相反,我的意思是如果上下文(名称空间)可以从被调用函数的上下文中推导出来