[Issue 20498] A way to initialize a struct of delegates with no-op stubs?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 20 19:44:36 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20498

--- Comment #1 from hsteoh at quickfur.ath.cx ---
Rainer Scheutze found this workaround:

------
void noop(int) {}
enum void delegate(int) dg_noop = (int x){ noop(x); };
struct S {
    void delegate(int) dg = dg_noop;
}
------

which can be applied to the original case as:
------
enum void delegate(Args) doNothing(Args...) = (Args args) {};
struct S {
    void delegate(int) dg1 = doNothing!int;
    void delegate(string, int) dg2 = doNothing!(string,int);
    ...
}
------

However he comments that it's a bug:

> I think it's a bug in the compiler. If you can assign an enum value, why
should the value itself not be good enough aswell?

--


More information about the Digitalmars-d-bugs mailing list