https://issues.dlang.org/show_bug.cgi?id=17953
Bolpat <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #3 from Bolpat <[email protected]> --- This can be done using templates: ```d int f(DG)(scope DG callback) { return callback("Hello, World"); } void main() @safe { import std.stdio; f((string str) { writeln(str); return 0; }); } ``` For opApply, for some reason, this works: ```d struct S { private int opApplyImpl(DG)(scope DG dg) { static if (is(DG : int delegate(string))) return dg("Hello, World!"); else return dg(0, "Hello, World!"); } alias opApply = opApplyImpl!(int delegate(string)); alias opApply = opApplyImpl!(int delegate(size_t, string)); } void main() @safe { import std.stdio; foreach (s; S()) { static assert(is(typeof(s) == string)); writeln(s); } foreach (i, s; S()) { static assert(is(typeof(i) == size_t)); static assert(is(typeof(s) == string)); writeln(i, " ", s); } } ``` --
