Is there any way to do something like this?

import std.stdio;

enum Foo : void function() {
        WOMBAT = () {writeln("Wombat");}
}

void doStuff(Foo f) {
        f();
}

int main() {
        doStuff( Foo.WOMBAT );
        
        return 0;
}

Currently, I get the errors:

hello.d(4): Error: non-constant nested delegate literal expression __lambda1 hello.d(12): Error: delegate hello.Foo.__lambda1 is a nested function and cannot be accessed from D main

I can fix it by declaring a function outside of Foo and setting WOMBAT = &fname, but it seems like I should be able to create a hidden lambda.

Reply via email to