Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 17:05:49 UTC, Timon Gehr wrote: ```d import std.stdio, std.traits, core.lifetime; auto partiallyApply(alias fun,C...)(C context){ return class(move(context)){ C context; this(C context) { foreach(i,ref c;this.context) c=move(context[i]); }

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Petar via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 17:05:49 UTC, Timon Gehr wrote: On 12/8/21 9:07 AM, Petar Kirov [ZombineDev] wrote: [...] Nice, so the error message is lying. Closure support deserves way more love in the compiler. I'm quite surprised that that hack worked, given that various very similar

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Petar via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 12:17:42 UTC, Stanislav Blinov wrote: On Wednesday, 8 December 2021 at 08:07:59 UTC, Petar Kirov [ZombineDev] wrote: ```d interface ICallable { void opCall() const; } alias Action = void delegate(); struct A { Action[] dg; } ``` At this point why

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Timon Gehr via Digitalmars-d-learn
On 12/8/21 9:07 AM, Petar Kirov [ZombineDev] wrote: On Wednesday, 8 December 2021 at 07:55:55 UTC, Timon Gehr wrote: On 08.12.21 03:05, Andrey Zherikov wrote: On Tuesday, 7 December 2021 at 18:50:04 UTC, Ali Çehreli wrote: I don't know whether the workaround works with your program but that

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 08:07:59 UTC, Petar Kirov [ZombineDev] wrote: ```d interface ICallable { void opCall() const; } alias Action = void delegate(); struct A { Action[] dg; } ``` At this point why not just call a spade a spade and store an array of ICallables directly?

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Petar via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 07:55:55 UTC, Timon Gehr wrote: On 08.12.21 03:05, Andrey Zherikov wrote: On Tuesday, 7 December 2021 at 18:50:04 UTC, Ali Çehreli wrote: I don't know whether the workaround works with your program but that delegate is the equivalent of the following struct

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Timon Gehr via Digitalmars-d-learn
On 08.12.21 03:05, Andrey Zherikov wrote: On Tuesday, 7 December 2021 at 18:50:04 UTC, Ali Çehreli wrote: I don't know whether the workaround works with your program but that delegate is the equivalent of the following struct (the struct should be faster because there is no dynamic context

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-07 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 7 December 2021 at 18:50:04 UTC, Ali Çehreli wrote: I don't know whether the workaround works with your program but that delegate is the equivalent of the following struct (the struct should be faster because there is no dynamic context allocation). Note the type of 'dg' is changed

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-07 Thread Ali Çehreli via Digitalmars-d-learn
On 12/7/21 7:30 AM, Andrey Zherikov wrote: > auto createDelegate(string s) > { > return { s.writeln; }; // Error: closures are not yet > supported in CTFE > } I don't know whether the workaround works with your program but that delegate is the equivalent of the following struct (the

Any workaround for "closures are not yet supported in CTFE"?

2021-12-07 Thread Andrey Zherikov via Digitalmars-d-learn
I have a struct `A` that stores delegates. The problem is that I'm getting "`Error: closures are not yet supported in CTFE`" if I create an compile-time constant value of type `A`: ```d struct A { void delegate()[] dg; } auto createDelegate(string s) { return { s.writeln; }; //