Voldemort declarations inside structs with ctor initialization

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Tue May 27 10:22:48 PDT 2014


On 5/27/14, 6:26 AM, Idan Arye wrote:
> On Tuesday, 27 May 2014 at 15:40:04 UTC, Luís Marques wrote:
>> On Tuesday, 27 May 2014 at 15:06:53 UTC, bearophile wrote:
>>>> BTW, why doesn't this example work with lambdas (a => a != 2)
>>>> instead of a string mixin ("a != 2")?
>>>
>>> I think lambda instantiations defines a different type. So it's
>>> incompatible.
>>
>> Incompatible with what? I meant changing it in both the declaration
>> and the initialization.
>
> Lambdas are not "cached", so each lambda is unique even if it's code is
> the same:
>
>      void main(){
>          pragma(msg,(int a)=>a); //prints __lambda1
>          pragma(msg,(int a)=>a); //prints __lambda2
>      }
>
>
> At any rate, you can't use lambdas(neither `delegate` nor `function`)
> when declaring a member of class or struct, since D will treat it as a
> method(rather than a static function) and complain about the `this`
> reference.

I think there was either or both a discussion and a bug report on this, 
but can't find either. Basically we need to clarify what it means to 
compare two function literals for equality. -- Andrei



More information about the Digitalmars-d mailing list