http://d.puremagic.com/issues/show_bug.cgi?id=6714
--- Comment #3 from Andrei Alexandrescu <[email protected]> 2011-12-24 09:32:58 PST --- (In reply to comment #2) > (In reply to comment #0) > > Consider: > > > > > > void foo (int function (int, int) a){} > > void bar (int delegate (int, int) a){} > > > > void main () > > { > > foo((a, b) { return a +b;}); > > bar((a, b) { return a +b;}); > > } > > > > Neither call works. The literal does not convert to the function or the > > delegate type. > > This works though: > bar((int a, int b) { return a + b;}); > Is that what you meant? If it is, then this is a duplicate of 3235. > > Or are argument types supposed to be deduced? If so, that's a major, > complicated feature and difficult to implement, I think it requires an extra > level of argument matching. When I discussed with Walter the matter a while ago, a possible approach was that the literal relying on deduction defines a local template function. For example, the code: foo((a, b) { return a +b;}); would be lowered into: static auto __lambda(T1, T2)(T1 a, T2 b) { return a + b; } foo(__lambda); The "static" is present because the compiler figured the lambda uses no state from the enclosing context. Built-in conversion mechanisms should take over from here on. This also brings the issue of automatically converting a function to a delegate. Walter disagrees with that, but I disagree with the basis of his disagreement. > It would need to be considered very carefully. > Eg, which of these calls are ambiguous? > > void bar ( double delegate(int, int) a ) {} > void bar ( int delegate (int, int) a ){} > > bar( (a, b) { return 1.0; } ); Works, goes to first overload. > bar( (a, b) { return 1.0f; } ); Doesn't work, no conversion possible for either overload. > bar( (a, b) { return a; } ); Depends on a's type. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
