On Sunday, 9 February 2014 at 13:03:47 UTC, Jakob Ovrum wrote:
On Sunday, 9 February 2014 at 12:48:36 UTC, Tim Volckmann wrote:
Any way to do something like this?
No, associative arrays cannot be transferred from compile-time
to runtime yet, due to implementation issues. The next best
thing you can do is to use a module constructor with a
generated body that fills the AA.
You mean using static this as follows?:
module myMain;
private
{
string function(string)[string] callbacks;
}
static this()
{
{
// do something like this:
//
// auto u = __traits(getFunctionsByAttribute, "MyUDA")
// foreach (myFunction; u)
// callbacks[myFunction.GetAttribute("MyUDA").Name] =
myFunction
}
}
void main(string[] args)
{
if (args[1] in callbacks)
{
callbacks[args[1]]("myString");
}
}
That's also possible... but how can I find all functions with
MyUDA?