Code example for function/delegate as template argument ?

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 4 04:25:19 PDT 2016


On Wednesday, 4 May 2016 at 10:58:04 UTC, chmike wrote:
> On Wednesday, 4 May 2016 at 06:59:00 UTC, Basile B. wrote:
>> . . .
>> void main(string[] args)
>> {
>>     alias fun = (a) => a.writeln;
>>     auto foo = Foo!fun("hello");
>> }
>
> Is this equivalent to Foo!(a => a.writeln) or is it required to 
> split this in two instructions as you did ? I also thought the 
> parenthesis around the lambda arguments are not required. Is 
> that right ?

Yes this is equivalent, the parens are not required. With a 
delegate literal they are: "auto foo = 
Foo!((a){a.writeln;})("hello");


More information about the Digitalmars-d-learn mailing list