Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » C++

Is decltype(vector())::iterator valid? If not, should i

 
Jump to:  
 
Chris Fairles
PostPosted: 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
PostPosted: 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! ]
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

Cytaty medycyna estetyczna wrocław Teksty piosenek Sen ubezpieczenie oc