Where statement
Michel Fortin
michel.fortin at michelf.com
Sun Jul 25 08:35:19 PDT 2010
On 2010-07-25 09:48:21 -0400, bearophile <bearophileHUGS at lycos.com> said:
> Michel Fortin:
>> Is this really an improvement over using a delegate literal?
>>
>> auto c = {
>> auto a = retrieve_a();
>> auto b = retrieve_b();
>> return sqrt(a*a + b*b);
>> };
>
> Cute :-) I have never seen this used in D code. I think you will need
> to add () at the end when @property get implemented fully.
Indeed, I forgot to add the (). Without it the type of 'c' is a
delegate (whether @property is implemented or not is irrelevant). I
just didn't test it properly before posting. Here's the revised version:
auto c = {
auto a = 1.0;
auto b = 2.0;
return a*a + b*b;
}();
I've never seen this in use either, but it looks like a nice pattern
for variables that require a complex initialization.
> I hope the D compiler is able to inline that delegate.
I think it does not currently. This bug report turns out to have a
patch for this exact issue however:
<http://d.puremagic.com/issues/show_bug.cgi?id=4440>
Put your vote on it if you want.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list