为什么在存在decltype的情况下范围解析失败? [英] Why does scope resolution fail in presence of decltype?
问题描述
我的理解是,decltype用于查询对象/变量的类型等。
It is my understanding that decltype is used to query the type of an objects/variables and so on.
从维基百科中的示例,如下:
From the examples present on wikipedia, such as the following:
int i;
decltype(i) x3; // type is int
我假设我可以这样做:
class A
{
public:
int a, b;
};
template<typename T>
struct IsClass
{
enum { Yes = std::is_class<T>::value };
enum { No = !Yes };
};
std::vector<A> v;
auto it = v.begin();
IsClass<decltype(it)::value_type>::Yes
是合法的:
IsClass<std::vector<A>::iterator::value_type>::Yes
不能编译,引用如下:错误C2039:'value_type':不是'
全局命名空间'的成员
Alas it wouldn't compile, citing the following: error C2039: 'value_type' : is not a member of '
global namespace''`
有关为什么范围解析在decltype存在时的行为的任何想法?
Any ideas as to why scope resolution was made to behave this way in presence of decltype?
PS:如果它有什么区别我使用MSVC2012(没有 Nov CTP)
P.S: If it makes any difference I'm using MSVC2012 (without the Nov CTP)
推荐答案
这是Visual C ++编译器中的一个已知错误。它还没有被固定为Visual C ++ 2013预览。您可以使用 std :: common_type
解决此问题:
This is a known bug in the Visual C++ compiler. It has not yet been fixed as of the Visual C++ 2013 Preview. You can work around this issue using std::common_type
:
IsClass<std::common_type<decltype(it)>::type::value_type>::Yes
^^^^^^^^^^^^^^^^^ ^^^^^^^
( std :: common_type
template参数产生该参数类型;它是标准化的C ++ 11等价于在元编程中早已使用的 identity
模板。)
(std::common_type
with a single template argument yields that argument type; it's the standardized C++11 equivalent of the identity
template that has long been used in metaprogramming.)
您可以在Microsoft Connect上找到公共错误报告:无法在scope操作符之前使用decltype 。如果这个问题对您很重要,请考虑将该错误报告。
You can find the public bug report on Microsoft Connect: Cannot use decltype before scope operator. If this issue is important to you, please consider upvoting that bug report.
这篇关于为什么在存在decltype的情况下范围解析失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!