On 12/24/2010 07:18 AM, Andrei Alexandrescu wrote:

What the... I didn't know you can do that. Thanks for the tip!

Andrei

It's great we can do that. Though it doesn't make D's compile-time introspection much easier to work with. For example, look how we get overloads of a function in the current module:

void foo(int) {}
void foo(int, int) {}

template Alias(A...)
{
    alias A Alias;
}

template Overloads(alias parent, string name)
{
    alias Alias!(__traits(getOverloads, parent, name)) Overloads;
}

mixin("alias Overloads!(" ~ .stringof[7..$] ~ ", \"foo\") foos;");

For a simple use case like that, we have to exploit two hacks:

1. The Alias template is required since __traits cannot be used directly in the alias declaration. I believe this is a compiler bug. 2. We have to mixin the module identifier extracted from stringof instead of referencing the current module symbolically.

With the special 'meta' namespace Don proposed long ago, the above example could probably be as simple as:

alias meta.overloadsOf(meta.currentModule, "foo") foos;

Reply via email to