|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - Array of member functions generated at compile time
Hi,
I'm trying to generate at compile-time an associative array of
function pointers to class member functions where the key in the array
is the name of the member function itself.
What my best attempt so far has been is as follows, which doesn't compile:
class ApplicationController
{
void function()[char[]] action_map;
this()
{
mixin ArrayMap!(build_code(__traits( derivedMembers,
ApplicationController )));
}
char[] build_code(invariant(char)[][] actions)
{
char[] code;
foreach(invariant(char)[] action; actions)
{
code ~= "action_map[\"" ~ action ~ "\"] = &(" ~ action ~ ");";
}
return code;
}
template ArrayMap(char[] code)
{
const ArrayMap = code;
}
}
Can anyone suggest other ways to achieve what I want to do? Or point
out where I might be going wrong in the above?
Many thanks
Jason
P.S. The compiler error I get is:
applicationcontroller.d(9): Error: expression
this.build_code(["action_map","_ctor","build_code","ArrayMap"]) is not
a valid template value argument
Apr 25 2008
"Jason Langenauer" <jason jasonlangenauer.com> wrote in message news:mailman.466.1209133945.2351.digitalmars-d-learn puremagic.com... Apr 25 2008
|