View mode: basic / threaded / horizontal-split · Log in · Help
May 24, 2008
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 == v2.value ? 0 : 1; })

However, is there a reason why DMD can't infer the types of v1 and v2? It  
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.value  
== v2.value ? 0 : 1; })

And, considering how foreach works, this:

'    .sort((v1, v2) { return v1.value < v2.value ? -1 : v1.value ==  
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/
Top | Discussion index | About this forum | D home