method generation by name
BCS
ao at pathlink.com
Mon Jul 23 13:26:43 PDT 2007
What is the best way to generate a method with a given name (as specified
by a const char[]) without having to build the whole thing as a string?
I was hoping this would work:
|template foo(R, char[] name, A...)
|{
| R mixin(name)(A a)
| {
| return d(a);
| }
|}
|
|mixin foo!(int, "hello", int);
|
|void main()
|{
| int i = hello(1);
|}
the best I have come up with is a bit hackish and has a few "issues".
|template foo(R, char[] name, A...)
|{
| R somthing(A a){return R.init;}
| mixin("alias somthing "~name~";");
|}
If a clean solution for this were made and class level static foreach were
to be implemented then auto implementation of an interface would be doable.
More information about the Digitalmars-d-learn
mailing list