www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Anonymous delegates and auto

Hi!

Using delegates and command chaining ... just awesome.

'    .sort((ref CTestFloatClass v1, ref CTestFloatClass v2) { return  =

v1.value < v2.value ? -1 : v1.value =3D=3D v2.value ? 0 : 1; })

However, is there a reason why DMD can't infer the types of v1 and v2? I=
t  =

infers the return type from the expression, but it can detect a type  =

mismatch in the delegate definition, so it has the information to make  =

this work:

'    .sort((auto v1, auto v2) { return v1.value < v2.value ? -1 : v1.val=
ue  =

=3D=3D v2.value ? 0 : 1; })

And, considering how foreach works, this:

'    .sort((v1, v2) { return v1.value < v2.value ? -1 : v1.value =3D=3D =
 =

v2.value ? 0 : 1; })

Any reason why this wouldn't work (probable parsing problems aside)?

-Mike

-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
May 24 2008