[Issue 2631] alias symbol this;

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 28 17:23:43 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2631





------- Comment #2 from jarrett.billingsley at gmail.com  2009-01-28 19:23 -------
(In reply to comment #1)
> Oh, and aliasing this should also nicely take care of the "inner name trick":
> 
> template Blah!(T) { alias T Blah; }
> 
> becomes
> 
> template Blah!(T) { alias T this; }
> 
> Much cleaner because it clarifies the intent and allows "one point of
> renaming".
> 

struct S
{
    mixin Blah!(int); // what happens?
}

If 'this' always refers to the template, you can't do cute things like mixing
in support for operations on values of type S.

If 'this' refers to the template sometimes and to the enclosing scope in
others, it's confusing.

Then again, I can't tell you how often I've mistyped the name of a template in
one of the nine places inside it, only to not find out until just the right
conditions are met and then the compiler dies with a "voids have no value"
error deep in some template instantiation which I can't figure out because it
doesn't print a damned traceback.  Sigh.  

Another problem with the "alias X this;" in templates is that it only works for
aliases.  You can't do "enum this = 5;".


-- 



More information about the Digitalmars-d-bugs mailing list