From -6827197583272518552
X-Google-Thread: f78e5,e8381186f8304247,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news4.google.com!news2.google.com!news.glorb.com!news.alt.net
From: Noah Roberts <noneed@toemailme.com>
Newsgroups: comp.std.c++
Subject: templates, lambda, and dependent names
Date: Wed,  5 Jan 2011 13:33:09 CST
Organization: Engineered Software Inc.
Lines: 55
Sender: std-cpp-request@vandevoorde.com
Approved: stephen.clamage@oracle.com
Message-ID: <MPG.278cef349bef7d41989693@news.mcleodusa.net>
Content-Type: text/plain; charset="us-ascii"
To: undisclosed-recipients:;
Return-Path: <cppmods@mcgurn.dreamhost.com>
X-Original-Date: Tue, 4 Jan 2011 08:48:27 -0800
X-Submission-Address: std-c++-submit@vandevoorde.com
Xref: g2news1.google.com comp.std.c++:3104


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.

-- 
http://crazyeddiecpp.blogspot.com/


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



