Code doesn't compile

Mohammad Sadegh Khoeini mskco.tp at gmail.com
Fri Jul 5 08:17:38 PDT 2013


On 7/5/13 7:05 PM, Adam D. Ruppe wrote:
> On Friday, 5 July 2013 at 11:23:55 UTC, Mohammad Sadegh Khoeini wrote:
>>   // auto u = Foo!(&b.fun)();  // doesn't work: vaiable b cannot be
>> read at compile time
>>   // auto v = Foo!(Baz!int.fun!int)();  //doesn't work: this for fun
>> needs to be type Baz not type Foo!(fun)
>
> Not a bug, I think at least, getting the address needs to be done at
> runtime and delegates need an address. The reason the literal works is
> literals can cheat at figuring out its variables.
>
> Wrapping it like you did for variable f is the easiest way to make it work.


Yes, but it's confusing.
What is great about D's meta programming is that it is very intuitive. 
However, the gotchas like that will surprise people. specifically that 
these kind of stuff can happen in the middle of a very complex code, 
which makes it very hard to find out the source of the problem.

I feel like the compiler in these kind of situations should be able to 
deduce on itself that &b.fun needs to wrapped on the site of its appearance.

The other side of this problem is how can I cheat the templating system 
so it would accept these kind of expressions?



More information about the Digitalmars-d mailing list