Is using function() in templates possible at all?

Laurent Tréguier laurent.treguier.sink at gmail.com
Thu Apr 12 11:17:01 UTC 2018


On Thursday, 12 April 2018 at 00:05:26 UTC, Nicholas Wilson wrote:
> There is, with template constraints:
>
> class SortedList(T, alias comparer)
>     if(is(typeof(comparer(T.init) : int))
> {
>     //...
> }

If the function is declared with explicit parameter types:
```
auto list = new SortedList!(Vector3, (Vector3 v) => v.y)();
```

Then the template guard can even have a full type definition:
```
class SortedList(T, alias comparer)
     if (is(typeof(comparer) :  int function(T)))
{
     //...
}
```


More information about the Digitalmars-d-learn mailing list