www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Non-global template cannot use local lambda

reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
I can't see why the following limitation:

class C
{
     void foo(alias Func)()
     {}
}

void main()
{
     auto c = new C();
     c.foo!(x => x)();  // <-- Compilation error
}

Error: template instance foo!(__lambda2) cannot use local 
'__lambda2(__T1)' as parameter to non-global template foo(alias Func)

Is this a bug?

I've noticed this problem in some of my online examples. The following 
line doesn't work with 2.059, where map() below is 
std.parallelism.TaskPool.map():

     auto results = map!(a => a.averageGrade)(students);

Ali
Jul 22 2012
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday, July 22, 2012 17:40:36 Ali =C3=87ehreli wrote:
 I can't see why the following limitation:
=20
 class C
 {
      void foo(alias Func)()
      {}
 }
=20
 void main()
 {
      auto c =3D new C();
      c.foo!(x =3D> x)();  // <-- Compilation error
 }
=20
 Error: template instance foo!(__lambda2) cannot use local
 '__lambda2(__T1)' as parameter to non-global template foo(alias Func)=
=20
 Is this a bug?
I'd say that it's a bug . If it's not, it definitely should be an enha= ncement. - Jonathan M Davis
Jul 22 2012
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 07/22/2012 06:08 PM, Jonathan M Davis wrote:
 On Sunday, July 22, 2012 17:40:36 Ali Çehreli wrote:
 I can't see why the following limitation:

 class C
 {
       void foo(alias Func)()
       {}
 }

 void main()
 {
       auto c = new C();
       c.foo!(x =>  x)();  //<-- Compilation error
 }

 Error: template instance foo!(__lambda2) cannot use local
 '__lambda2(__T1)' as parameter to non-global template foo(alias Func)

 Is this a bug?
I'd say that it's a bug . If it's not, it definitely should be an
enhancement.
 - Jonathan M Davis
Thanks and sorry for the noise. I should have checked bugzilla first: http://d.puremagic.com/issues/show_bug.cgi?id=3051 http://d.puremagic.com/issues/show_bug.cgi?id=3052 This one is opened by David Simcha when implementing std.parallelism: http://d.puremagic.com/issues/show_bug.cgi?id=5710 Then I guess my examples used to work due to dmd bugs that must have gotten fixed during the short lambda syntax implementation. Ali
Jul 22 2012