But... I don't want my delegates to be lazy - breeding advice

BCS BCS at pathlink.com
Thu Aug 24 18:35:21 PDT 2006


Bruno Medeiros wrote:
> BCS wrote:
> 
>> Andy Knowles wrote:
>>>
>>> 1) While in void foo(lazy int x) will x be evaluated using x() or 
>>> just x?  Either one could lead to confusion.
>>>
>>
>> I'd go for "x()", because
>>
>> 1> it more closely reflects what is actually happening.
>>
>> 2> it allows x to be used to refer to the delegate
>>
> 
> Indeed, "x()" is a better usage, however, if x is a delegate, then the 
> "x" usage will still be allowed, due to the implicit call syntax (aka 
> property syntax).

Delegates can't be used with implicit call syntax. You get a "can't 
convert T delegate() to T" error.

void main()
{
	int dg() {  return 1; }

	int i = dg;
	int delegate() t = &dg;
	i = t;
}



d.d(7): cannot implicitly convert expression (t) of type int delegate() 
to int



More information about the Digitalmars-d mailing list