【发布时间】:2013-07-16 11:01:19
【问题描述】:
我刚刚意识到尝试通过 decltype 获取函数的返回类型不涉及 VS2012 上的 ADL(argument-dependent-lookup)(使用 cl.exe V17.00.60610.1 测试)。
下面的例子
#include <stdio.h>
#include <typeinfo>
namespace A {
int Func(void const *) {
printf("A::Func(void const *)\n");
return 0;
}
template <typename T> void Do(T const &t) {
Func(&t);
}
template <typename T> void PrintType(T const &t) {
printf("Type: %s\n", typeid(decltype(Func(&t))).name());
}
}
namespace B {
struct XX { };
float Func(XX const *) {
printf("B::Func(XX const *)\n");
return 0.0f;
}
}
int main(int argc, char **argv) {
B::XX xx;
A::Do(xx);
A::PrintType(xx);
return 0;
}
给
B::Func(XX const *)
Type: int
在 VS2012 上
但是(预期的):
B::Func(XX const *)
Type: f
在 gcc 4.7.3 上。
所以 ADL 在调用函数时有效(输出中的第 1 行),但在 VS2012 上的 decltype 中使用时无效。
或者我错过了一些不同的点?
【问题讨论】:
-
VS2012
decltype支持很差(搜索“表达式 SFINAE”并哭泣),所以我并不感到惊讶。 -
许多 C++11 特性在 VS2012 和随后的 11 月 CTP 中非常具有 alpha 质量。据说在 VS2013 预览版中有一长串已修复的错误(Express 目前可供下载)。你可以在那里碰碰运气。
-
那么,自 VS2012 以来,非常频繁的更新以解决错误并添加 MS 想要遵循的新功能的新方法呢...那么呢...幸运的是,我的编译器选择不受限制这个特定的项目,所以我所有的希望和梦想都寄托在 VS2013 上:-)
标签: c++ visual-studio-2012 c++11 decltype argument-dependent-lookup