On Sun, 23 Oct 2011 02:59:48 -0400, J Arrizza <[email protected]> wrote:
The idea here was to create a base class. That base class would have a
function register() which took a function name or function pointer, and
create a delegate at compile time. register() would add the delegate and
the function name as a string into the hash. At runtime, I pass in the
string, get the delegate and invoke the function.
So I need both the function name as a symbol (to create the delegate) and
the function name as a string. In c++ I'd use the preprocessor to convert
the symbol to a string via "#" (stringify).
If D doesn't have this, the callers will have to do:
register(bob, "bob");
which is a little tedious.
BTW I tried:
public void register(string name) {
auto func = __traits(getMember, this, name);
but __traits() only works at compile time, but variable name is only
available at run-time....
John
Okay, I'm a little confused about exactly what you want to do, but I think you
want something like:
string foo(alias T)() {
T++;
return T.stringof;
}
int x = 0;
assert(foo!x == "x");
assert(x == 1);
alias template parameters give you access to actual variables/functions, which
is what you seem to be asking for.