Is using function() in templates possible at all?

Nicholas Wilson iamthewilsonator at hotmail.com
Thu Apr 12 00:05:26 UTC 2018


On Wednesday, 11 April 2018 at 22:13:33 UTC, Sjoerd Nijboer wrote:
> On Wednesday, 11 April 2018 at 21:29:27 UTC, Alex wrote:
>> I would say, alias template parameter is your friend.
>> https://dlang.org/spec/template.html#TemplateAliasParameter
>>
>> class SortedList(T, alias comparer)
>
> It works, thank you!
> But just to be shure, there's no way to have this more strongly 
> typed in D so I can enforce that `comparer`is a funciton or 
> delegate with a specific definition?


There is, with template constraints:

class SortedList(T, alias comparer) if(is(typeof(comparer(T.init) 
: int))
{
     //...
}


More information about the Digitalmars-d-learn mailing list