Bug 9838 – Allow calling aliased method on an object
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-30T12:24:00Z
Last change time
2016-08-27T23:14:55Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-03-30T12:24:45Z
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.
Comment #1 by andrej.mitrovich — 2016-08-27T23:14:55Z
This is asking for too much magic. At best it should be a DIP, but I don't think we should go there.