Is using function() in templates possible at all?

Alex sascha.orlov at gmail.com
Thu Apr 12 11:53:21 UTC 2018


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
	}
}
´´´


More information about the Digitalmars-d-learn mailing list