Get identifier of "this"
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Sep 17 11:01:35 PDT 2012
On 9/17/12, Andre <andre at s-e-a-p.de> wrote:
> Get identifier of "this"
You can't really get that info at runtime, a class object isn't bound
to a name, 'this' has no identifier. Symbols (like variables) have
identifiers, not objects.
> public class Bank{
Unnecessary, declarations are public by default.
> public enum test()
'enum' has no meaning in a return type. Either it's 'auto' which
infers the return type from the function body, or it's a specific type
like 'string' (or void if no return type).
> {
> return "writeln(\""~__traits(identfier, this)~"\");";
typo: identifier, not identfier
> }
> }
>
> public static void main(){
public and static have no meaning here.
> During compile time, following code should be generated:
> writeln("b");
It's not possible to mixin a string at compile-time from a string
returned from a method of an object which is instantiated at runtime.
If you want the identifier of the variable then you don't have to deal
with the 'this' reference at all, e.g.:
@property string test(alias symb)()
{
return "writeln(\"" ~ __traits(identifier, symb) ~ "\");";
}
class Bank { }
void main()
{
Bank b = new Bank;
mixin(test!b);
}
Your original sample does cause a compiler ICE but I don't know if
it's worth filing since the code was invalid.
More information about the Digitalmars-d-learn
mailing list