|  | Is decltype(vector())::iterator valid? If not, should i |  | |
| | | Chris Fairles |  |
| Posted: Sat Aug 30, 2008 3:08 pm Post subject: Is decltype(vector())::iterator valid? If not, should i |  |
Take the following snip:
#include <vector>
int main() { decltype(vector<int>())::iterator i; }
Currently gcc 4.4.0 mainline issue a diagnostic: expected initializer before 'i'.
So, looking at n2723, "decltype (expression)" is a simple-type- specifier and am I correct in saying that this is the reason why the snip is ill-formed (i.e.the scope resolution operator can't be applied to a simple-type-specifier)?
You can make the snip work by re-defining decltype using a macro:
#include <vector>
#define decltype(x) ::std::identity<decltype(x)>::type
int main() { decltype(vector<int>())::iterator i; }
and voila, it now works as expected. So why wouldn't everyone just define decltype like that and be able to apply the scope resolution operator to decltype()'s?
Chris
-- [ See LINK for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
| |
| | | Triple-DES |  |
| Posted: Sun Aug 31, 2008 8:58 am Post subject: Re: Is decltype(vector())::iterator valid? If not, shou |  |
On 30 Aug, 17:08, Chris Fairles <chris.fair...@gmail.com> wrote:
| Quote: | Take the following snip:
#include <vector
int main() { decltype(vector<int>())::iterator i;
}
Currently gcc 4.4.0 mainline issue a diagnostic: expected initializer before 'i'.
So, looking at n2723, "decltype (expression)" is a simple-type- specifier and am I correct in saying that this is the reason why the snip is ill-formed (i.e.the scope resolution operator can't be applied to a simple-type-specifier)?
|
I asked the very same question some time ago. According to Daveed Vandevoorde: "The grammar doesn't allow a decltype construct to appear as a qualifier. It has to be a namespace-name, a class-name, a typedef- name, or an enum-name"
DP
-- [ See LINK for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
| |
|
|