a function pointer or an aggregate type with opCall defined.
A delegate with the context pointer pointing to nothing.
void doStuff() { writeln("Hello, world."); } void runDelegate(void delegate() myDelegate) { myDelegate(); } auto delegateToPass = toDelegate(&doStuff); runDelegate(delegateToPass); // Calls doStuff, prints "Hello, world."
static int inc(ref uint num) { num++; return 8675309; } uint myNum = 0; auto incMyNumDel = toDelegate(&inc); auto returnVal = incMyNumDel(myNum); assert(myNum == 1);
Convert a callable to a delegate with the same parameter list and return type, avoiding heap allocations and use of auxiliary storage.