Re: array of functions/delegates

2019-12-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/24/19 8:52 AM, MoonlightSentinel wrote: On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote: I am trying to create an array of functions inside a struct. struct S {   void f1() {}   void f2() {}   alias Func = void function();  immutable Func[2] = [&f1, &f2] } What I go

Re: array of functions/delegates

2019-12-24 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 13:13:12 UTC, MoonlightSentinel wrote: On Tuesday, 24 December 2019 at 10:40:16 UTC, Mike Parker wrote: struct S {} void f1(S s) {} void f2(S s) {} alias Func = immutable(void function()); immutable Func[2] funcs = [cast(Func)&f1, cast(Func)&f2]; Though, it's n

Re: array of functions/delegates

2019-12-24 Thread MoonlightSentinel via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote: I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [&f1, &f2] } What I got: Error: non-constant expression '&am

Re: array of functions/delegates

2019-12-24 Thread MoonlightSentinel via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 13:13:12 UTC, MoonlightSentinel wrote: On Tuesday, 24 December 2019 at 10:40:16 UTC, Mike Parker wrote: struct S {} void f1(S s) {} void f2(S s) {} alias Func = immutable(void function()); immutable Func[2] funcs = [cast(Func)&f1, cast(Func)&f2]; Though, it's n

Re: array of functions/delegates

2019-12-24 Thread MoonlightSentinel via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 10:40:16 UTC, Mike Parker wrote: struct S {} void f1(S s) {} void f2(S s) {} alias Func = immutable(void function()); immutable Func[2] funcs = [cast(Func)&f1, cast(Func)&f2]; Though, it's not clear to me wy the one requires casting the pointer type and the oth

Re: array of functions/delegates

2019-12-24 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote: I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [&f1, &f2] } What I got: Error: non-constant expression '&am

Re: array of functions/delegates

2019-12-24 Thread Alex via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote: I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [&f1, &f2] } What I got: Error: non-constant expression '&am

array of functions/delegates

2019-12-23 Thread Rumbu via Digitalmars-d-learn
I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [&f1, &f2] } What I got: Error: non-constant expression '&f1' Tried also with delegates (since I am in a struct

Re: array of functions

2009-06-05 Thread Robert Clipsham
Jarrett Billingsley wrote It can't evaluate &func at compile-time because there is no way to create a delegate at compile-time. I believe that LDC used to support this, but had to remove the functionality due to some bugs with it/to be compatible with dmd.

Re: array of functions

2009-06-04 Thread Trass3r
Jarrett Billingsley schrieb: On Thu, Jun 4, 2009 at 12:42 PM, Trass3r wrote: I tried to use a function lookup table to quickly access a particular one. But the compiler (dmd1) complains about Error: non-constant expression & func I guess because it's used inside a class since &func is of type

Re: array of functions

2009-06-04 Thread Jarrett Billingsley
On Thu, Jun 4, 2009 at 12:42 PM, Trass3r wrote: > I tried to use a function lookup table to quickly access a particular one. > But the compiler (dmd1) complains about > Error: non-constant expression & func > > I guess because it's used inside a class since &func is of type function, > not delegat

array of functions

2009-06-04 Thread Trass3r
I tried to use a function lookup table to quickly access a particular one. But the compiler (dmd1) complains about Error: non-constant expression & func I guess because it's used inside a class since &func is of type function, not delegate? Here's a stripped down example: protected Object fu