Is using function() in templates possible at all?
Laurent Tréguier
laurent.treguier.sink at gmail.com
Thu Apr 12 13:34:07 UTC 2018
On Thursday, 12 April 2018 at 11:53:21 UTC, Alex wrote:
> On Thursday, 12 April 2018 at 11:17:01 UTC, Laurent Tréguier
> wrote:
>> If the function is declared with explicit parameter types:
>
> There are cool things possible, if the param type is explicitly
> typed :)
>
> ´´´
> import std.traits;
>
> void main()
> {
> auto list = new SortedList!((Vector3 v) => v.y)();
> list.foo(Vector3.init);
> }
>
> struct Vector3 { float x, y, z; }
>
> class SortedList(alias comparer) if(is(ReturnType!comparer :
> float))
> {
> alias T = Parameters!comparer[0];
>
> T[] array;
>
> auto foo(T t)
> {
> // do stuff
> }
> }
> ´´´
Getting rid of redundancy. Now that's nice !
More information about the Digitalmars-d-learn
mailing list