Is there a way to get an alias to a symbol relative to the current location? I'm looking for a general solution but I'll show an example to demonstrate one use case.

Say we want to access the alias to the current function symbol. Obviously we can use the name of the current function, i.e.

    void foo()
    {
        alias TheAliasWeWant = foo;
    }

but this means the code must be modified for every function, i.e.

    void foo1()
    {
        alias TheAliasWeWant = foo1;
    }
    void foo2()
    {
alias TheAliasWeWant = foo1; // uh oh, should be foo2, copy paste error
    }

is there a way to implement a library function/template that can do this?

    void foo1()
    {
        alias TheAliasWeWant = currentFunctionAlias();
    }
    void foo2()
    {
alias TheAliasWeWant = currentFunctionAlias(); // can't make copy/paste error
    }

Note that this is similar to the special keywords like __FUNCTION__, __MODULE__, the difference being that we want a symbol instead of a string. We may be able to create an interesting solution to the function case where we unmangle the __FUNCTION__ result and then mixin the resulting string, but I'm also looking for the ability to get an alias to the current type, i.e.

struct Foo
{
    void foo()
    {
        alias TheAliasWeWant = Foo;
        alias TheAliasWeWant = currentTypeAlias(); // possible?
    }
}

Reply via email to