On 6/14/12, Jacob Carlborg <d...@me.com> wrote: > Is it possible, somehow, to emulate adding new _static_ methods to a > class, something like this:
Of course there is, this is D not Java! Enjoy: import std.stdio; import std.metastrings; void fooBar(T : Foo)(int x) { writeln(x); } struct Foo { static auto opDispatch(string name, Params...)(Params params) { enum strOf = typeof(this).stringof; enum str = Format!("return .%s!%s(params);", name, strOf); mixin(str); } } void main() { Foo.fooBar(4); }