class Foo { DelegateFormatter formatPretty() { return DelegateFormatter(&prettyFormatter); } private void prettyFormatter(StringSink sink) { sink("the pretty format"); } DelegateFormatter formatUgly() { return DelegateFormatter(&uglyFormatter); } private void uglyFormatter(StringSink sink) { sink("the ugly format"); } } Foo foo; writefln("foo pretty = %s", foo.formatPretty()); writefln("foo ugly = %s", foo.formatUgly());
A delegate formatter allows a delegate to behave as format function. A common use case for this would be to have multiple ways to format a class.