Re: trouble with decltype
Am 06.04.2012 21:55, schrieb Brendan:
I'm getting some weird behavior from decltype, at least on my compiler
(g++ 4.6). Could someone explain whether this is standard and why?
Consider:
std::vector<int> vec;
decltype(vec)::value_type x;
The second line gives me the error:
expected initializer before "x"
I'm not sure what that means in this context. I'd expect my decltype
code to be the same as:
std::vector<int>::value_type x;
Is :: prohibited to be used with decltype? If so, what's the best
workaround? Just pass decltype to an intermediary template like so?
I just notice that I forgot to respond to your last question in my
previous reply: The most simple workaround for a defective compiler
should be to split the declaration of x into two parts:
std::vector<int> vec;
typedef decltype(vec) c_t;
c_t::value_type x;
This should work.
foo<decltype(bar)>::value_type
Seems kind of inconvenient if that is the case...
I agree and it should not be necessary to introduce an additional type
layer (like foo) for this simple request.
If the two-step declaration is no good workaround for you, you should
consider to switch to gcc 4.7.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]