From 4713187412853197631
X-Google-Thread: f78e5,e8381186f8304247
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,UTF8
Path: g2news1.google.com!news4.google.com!news1.google.com!news.glorb.com!news.alt.net
From: Inconnu <shirarenai@yandex.ru>
Newsgroups: comp.std.c++
Subject: Re: templates, lambda, and dependent names
Date: Sat,  8 Jan 2011 19:40:36 CST
Organization: http://groups.google.com
Lines: 65
Sender: std-cpp-request@vandevoorde.com
Approved: stephen.clamage@oracle.com
Message-ID: <2621c508-cc6e-40f0-8298-3f6ef3fc9fec@c2g2000yqc.googlegroups.com>
References: <MPG.278cef349bef7d41989693@news.mcleodusa.net>
Content-Type: text/plain; charset=UTF-8
To: undisclosed-recipients:;
Return-Path: <cppmods@mcgurn.dreamhost.com>
X-Original-Date: Fri, 7 Jan 2011 19:25:18 -0800 (PST)
X-Submission-Address: std-c++-submit@vandevoorde.com
Xref: g2news1.google.com comp.std.c++:3106


On 5 янв, 22:33, Noah Roberts <non...@toemailme.com> wrote:
> I've run into something I did not expect when trying to create a lambda
> function within a templated function, namely dependent names are not
> behaving as I would expect.  I'm trying to find out if I'm working with
> a bad implementation or if my intuition and experience fail in this
> case.
>
> template < typename T >
> function<void()> f()
> {
>    return []() { typedef typename T::type type; };
>
> }
>
> This one fails for two reasons: 1) the compiler insists that typename is
> invalid here and 2) it doesn't see the T symbol.  Taking the typename
> out gets rid of the first error.
>
> template < typename T >
> struct get_type { typedef typename T::type type; };
>
> template < typename T >
> function<void()> f()
> {
>    return [](){ typedef typename get_type<T>::type type; };
>
> }
>
> This one only fails because the compiler insists that typename can't be
> used here.  Getting rid of that and the program compiles and works
> correctly.
>
> My original code uses boost's function, but afaict that wouldn't make
> any difference.
>
> I've tried various other places before coming here.  Everyone is
> guessing though.  Best reply so far is this one:http://stackoverflow.com/questions/4589056/templates-typename-lambda-
> dependent-names-not-dependent/4593286#4593286
>
> I'm looking for something definitive though.  Is "icecrime's" answer
> correct?
>
> The compiler is MSVC2010 but I'm looking for what the standard specifies
> here.
>
> Thanks.
>

Yes, "icecrime's" answer is correct, "Motti's" answer is wrong. The
standard though, as far as I understand, doesn't permit now an
implicit conversion from lambda expression to function<...> or any
other user-written class. And, as far as MSVC is concerned, it looks
very much like that it doesn't parse template function bodies at all,
it parses them during instantiation, substituting template parameters
with their values, that's why it isn't strange that 'typenames' only
hamper it to work.


-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



