From 9001552840203100101
X-Google-Thread: f78e5,e8381186f8304247
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,UTF8
Path: g2news2.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 09 Jan 2011 10:40:02 -0600
Return-Path: <cppmods@mcgurn.dreamhost.com>
Sender: std-cpp-request@vandevoorde.com
Approved: stephen.clamage@oracle.com 
Message-ID: <gtjWo.561811$De6.194965@en-nntp-01.dc1.easynews.com>
Newsgroups: comp.std.c++
From: Joe Gottman <josephgottman@comcast.net>
Subject: Re: templates, lambda, and dependent names 
Organization: EasyNews, UseNet made Easy!
References: <MPG.278cef349bef7d41989693@news.mcleodusa.net>
	<2621c508-cc6e-40f0-8298-3f6ef3fc9fec@c2g2000yqc.googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Original-Date: Sun, 09 Jan 2011 09:18:56 -0500
X-Submission-Address: std-c++-submit@vandevoorde.com
To: undisclosed-recipients:;
Date: Sun,  9 Jan 2011 10:38:05 CST
Lines: 76
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-BPNmSKW4NXoSaOlg3o6YFmv8v+nnWAHe2npS6stF3P5yj2tcAWvSdp6TaQzZVbbdticF4dLe+iWi0Yq!uzcGdVTYspvaS6vfVk19po33POQ5S5xivrxyH01DoCkzcL5o7vBIqfRP2Z/FjnoDguda+ajp3KPH!U620kbaP
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 4155
Xref: g2news2.google.com comp.std.c++:3107


On 1/8/2011 8:40 PM, Inconnu wrote:
>
> 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.

Actually, I think it does.  std::function has the non-explicit constructor
	template<class F> function(F f)

I'm pretty sure that if the parameter types and return types of the
lambda function match those of the function template that implicit
conversion will occur.

Joe Gottman


-- 
[ 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                      ]



