March 30, 2013 [Issue 9838] New: Allow calling aliased method on an object | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9838 Summary: Allow calling aliased method on an object Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-30 12:24:45 PDT --- I could really use this feature in D: auto callFunc(alias func, Class)(Class object) { func(object); // ok } auto callMeth(alias meth, Class)(Class object) { object.meth(); // denied } void foo(C c) { } class C { void foo() { } } void main() { C c = new C; callFunc!(foo)(c); callMeth!(C.foo)(c); } The benefit here is that we won't have to use __traits(identifier, meth), and especially won't have to use a string mixin. For example to make the above work properly one has to write: import std.string; auto callMeth(alias meth, Class)(Class object) { mixin(format("object.%s();", __traits(identifier, meth))); } Or you can use string appending, pick your poison. It's very ugly, even if you decide to use q{}. String mixins are generally very error-prone and hard to debug, this feature would alleviate that. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation