Initializing a table of delegates with no-op stubs
Rainer Schuetze
r.sagitario at gmx.de
Sat Jan 11 09:40:57 UTC 2020
On 09/01/2020 23:02, H. S. Teoh wrote:
> void dummy(int) {}
> struct S {
> void function(int) f1 = &dummy; // OK
>
> // But it doesn't work with delegates, no way, no how:
> void delegate(int) dg1 = &dummy; // NG
> void delegate(int) dg2 = (int) {}; // NG
> void delegate(int) dg3 = (int) => dummy(0); // NG
> }
>
[...]
> Am I missing something obvious??
>
This seems to work:
void noop(int) {}
enum void delegate(int) dg_noop = (int x){ noop(x); };
struct S
{
void delegate(int) dg = dg_noop;
}
More information about the Digitalmars-d
mailing list