C ++ 0x decltype和范围解析运算符 [英] C++0x decltype and the scope resolution operator
问题描述
使用Foo这样的类:
struct Foo {static const int i = 9; };
我发现GCC 4.5将拒绝以下内容
Foo f;
int x = decltype(f):: i;
如果我使用中间typedef,它将起作用,例如:
typedef decltype(f)ftype;
int x = ftype :: i;
但是我更喜欢保持命名空间整洁。我认为优先顺序可能是个问题,因此我也尝试使用括号,但没有运气。
它是有效的C ++ 0x,是不可能的吗?
说 decltype(f):: i
。 GCC尚不支持。您可以使用身份模板来解决它
template< typename T>结构体身份{typedef T type; };
int x = identity< decltype(f)> :: type :: i;
身份
是<$ c的一部分$ c> boost :: mpl 命名空间。
With a class such as Foo:
struct Foo { static const int i = 9; };
I find that GCC 4.5 will reject the following
Foo f;
int x = decltype(f)::i;
It will work if I use an intermediate typedef, such as:
typedef decltype(f) ftype;
int x = ftype::i;
but I prefer to keep the namespace clean. I thought precedence may be an issue, so I've also tried parentheses, but no luck. Is it impossible as presented, or is there a piece of syntax that can help me?
It is valid C++0x to say decltype(f)::i
. GCC just doesn't support it yet. You can work it around with an identity template
template<typename T> struct identity { typedef T type; };
int x = identity<decltype(f)>::type::i;
identity
is part of the boost::mpl
namespace.
这篇关于C ++ 0x decltype和范围解析运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!