Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Martin Nowak
On Sat, 03 Sep 2011 23:03:18 +0200, Timon Gehr wrote: On 09/03/2011 03:12 PM, Martin Nowak wrote: On Sat, 03 Sep 2011 11:50:25 +0200, Christophe wrote: void main() { auto foo = (int x = 10){ /* */ } void delegate() bar = { return foo(); } } the compiler could in theory just automatically i

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Timon Gehr
On 09/03/2011 11:34 AM, Jacob Carlborg wrote: On 2011-09-02 21:11, Andrej Mitrovic wrote: Code: void main() { auto foo = (int x = 10){ /* */ }; void delegate() bar = foo; } Since foo takes an argument that already has a default it can be used as a simple `void delegate()`, so maybe it makes se

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Timon Gehr
On 09/03/2011 03:12 PM, Martin Nowak wrote: On Sat, 03 Sep 2011 11:50:25 +0200, Christophe wrote: void main() { auto foo = (int x = 10){ /* */ } void delegate() bar = { return foo(); } } the compiler could in theory just automatically insert a thunk like this. That sounds reasonable. This

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Andrei Alexandrescu
On 9/2/11 9:52 PM, Andrej Mitrovic wrote: On 9/3/11, Timon Gehr wrote: Related: I think that function pointers should implicitly decay to delegates. This would allow the compiler to optimize some delegate literals to function pointers if they don't access the outer scope, without breaking any c

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Martin Nowak
On Sat, 03 Sep 2011 11:50:25 +0200, Christophe wrote: void main() { auto foo = (int x = 10){ /* */ } void delegate() bar = { return foo(); } } the compiler could in theory just automatically insert a thunk like this. That sounds reasonable. This look like a library solution w

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Christophe
> void main() > { > auto foo = (int x = 10){ /* */ } >  void delegate() bar = { return foo(); } > } > > the compiler could in theory just automatically insert a thunk like > this. That sounds reasonable.

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-03 Thread Jacob Carlborg
On 2011-09-02 21:11, Andrej Mitrovic wrote: Code: void main() { auto foo = (int x = 10){ /* */ }; void delegate() bar = foo; } Since foo takes an argument that already has a default it can be used as a simple `void delegate()`, so maybe it makes sense for `foo` to be able to implicitl

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-02 Thread Andrej Mitrovic
On 9/3/11, Timon Gehr wrote: > Related: I think that function pointers should implicitly decay to > delegates. This would allow the compiler to optimize some delegate > literals to function pointers if they don't access the outer scope, > without breaking any code that wants to use such a function

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-02 Thread Timon Gehr
On 09/02/2011 11:49 PM, Andrej Mitrovic wrote: On 9/2/11, Vladimir Panteleev wrote: On Fri, 02 Sep 2011 22:11:50 +0300, Andrej Mitrovic wrote: So maybe this type of conversion is impossible in the first place due to how arguments are passed? Yes. The default value is pushed on the stack a

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-02 Thread Andrej Mitrovic
On 9/2/11, Vladimir Panteleev wrote: > On Fri, 02 Sep 2011 22:11:50 +0300, Andrej Mitrovic > wrote: > >> So maybe this type of conversion is impossible in the first place due >> to how arguments are passed? > > Yes. The default value is pushed on the stack at the call site. Yeah, I should have t

Re: Conversion of delegate with default arguments to delegate with less arguments?

2011-09-02 Thread Vladimir Panteleev
On Fri, 02 Sep 2011 22:11:50 +0300, Andrej Mitrovic wrote: So maybe this type of conversion is impossible in the first place due to how arguments are passed? Yes. The default value is pushed on the stack at the call site. I don't know all the technical tidbits, but from a user's point of

Conversion of delegate with default arguments to delegate with less arguments?

2011-09-02 Thread Andrej Mitrovic
Code: void main() { auto foo = (int x = 10){ /* */ }; void delegate() bar = foo; } Since foo takes an argument that already has a default it can be used as a simple `void delegate()`, so maybe it makes sense for `foo` to be able to implicitly convert to such a type. Unfortunately doing a