Re: Constant function/delegate literal

2012-01-17 Thread Timon Gehr
On 01/17/2012 05:02 PM, Don Clugston wrote: On 15/01/12 20:35, Timon Gehr wrote: On 01/14/2012 07:13 PM, Vladimir Matveev wrote: Hi, Is there a reason why I cannot compile the following code: module test; struct Test { int delegate(int) f; } Test s = Test((int x) { return x + 1; }); void m

Re: Constant function/delegate literal

2012-01-17 Thread Don Clugston
On 15/01/12 20:35, Timon Gehr wrote: On 01/14/2012 07:13 PM, Vladimir Matveev wrote: Hi, Is there a reason why I cannot compile the following code: module test; struct Test { int delegate(int) f; } Test s = Test((int x) { return x + 1; }); void main(string[] args) { return; } dmd 2.057 say

Re: Constant function/delegate literal

2012-01-15 Thread Timon Gehr
On 01/14/2012 07:13 PM, Vladimir Matveev wrote: Hi, Is there a reason why I cannot compile the following code: module test; struct Test { int delegate(int) f; } Test s = Test((int x) { return x + 1; }); void main(string[] args) { return; } dmd 2.057 says: test.d(7): Error: non-co

Re: Constant function/delegate literal

2012-01-15 Thread H. S. Teoh
On Sun, Jan 15, 2012 at 02:21:04PM +, Vladimir Matveev wrote: > Thanks, that was very helpful. Module initializer works like a charm. > Shame I didn't find it in the documentation. Thanks again. [...] It's discussed briefly in Andrei's book (section 11.3, p.356). T -- If it's green, it's b

Re: Constant function/delegate literal

2012-01-15 Thread Vladimir Matveev
Thanks, that was very helpful. Module initializer works like a charm. Shame I didn't find it in the documentation. Thanks again. Best regards, Vladimir.

Re: Constant function/delegate literal

2012-01-14 Thread Andrej Mitrovic
I guess these are CTFE (compile-time function evaluation) issues, someone else might know more. A workaround is to use a module constructor which will run before main(): struct Test { int delegate(int) f; } Test s; static this() { s = Test((int x) { return x + 1; }); } Note that 's' is t