How does D allow delegates as template parameters?
问题 In "The D Programming Language" by Andrei Alexandrescu, there's an example where a delegate is taken as a template parameter: T[] find(alias pred, T)(T[] input) if(is(typeof(pred(input[0])) == bool)) { for(; input.length > 0; input = input[1 .. $]) { if (pred(input[0])) break; } return input; } unittest { int[] a = [1,2,3,4,-5,3,-4]; int z = -2; auto b = find!(delegate(x) { return x < z; })(a); asssert(b == a[4..$]); } Alexandrescu explains that this works because a delegate is actually a fat