On 05/01/2012 04:02 AM, Mehrdad wrote:
Wha..?!

I can't believe delegates work so poorly in D...

It is not the delegates, it is the type deduction algorithm for implicit function template instantiation. The issue is that the parameters do not cross-talk, which means R is not known during matching: How to detect the argument type from bool delegate(ElementType!R) alone if R is not known? The obvious solution would be to use an actual inference algorithm that uses information that can be gained from other parameters as well as information already known from the current parameter.

You might want to file an enhancement request, because this exact thing seems to trip up many programmers. (i.e. it would be a lot more intuitive and convenient if it worked.)


they're practically
unusable unless you're passing them as template parameters (which brings
on its own set of bugs)...

I haven't encountered those so far.


Seems like every time I try to escape a bug somehow, another one pops up :(


The situation is improving. Furthermore, there is a very large subset of the language that is already very usable.

Another way to make your code compile:

private import std.range;
void filter(R,S)(R, bool delegate(S)) if(is(S==ElementType!R)){ }
void main() { [1, 2, 3].filter((int x) { return x < 3; }); }

Reply via email to