[Article Submission] Have Your Efficiency, and Flexibility Too

Timon Gehr timon.gehr at gmx.ch
Wed Jun 1 07:32:10 PDT 2011


Steven Schveighoffer wrote:
> I think there are certain special situations where you can use
> typeof(this).  For example, as the return type for a static method.
>
> *looks for doc*  Couldn't find any documentation on it...
>
> It's somewhat like static this, which is inflexible in how you write it.
>
> -Steve

It is not documented in detail but it is there =).
See: http://www.digitalmars.com/d/2.0/declaration.html
"1. typeof(this) will generate the type of what this would be in a non-static
member function, even if not in a member function. "

Therefore it is not special cased, but is supposed to work universally.

That it does not work for Nick is probably a bug, not a sensible and thought-out
limitation. It can be very handy for Metaprogramming, this needs to get fixed at
some point.

@Nick: Can you try to deduce a minimal test case? (Or provide the full listing of
the code?)


Timon


More information about the Digitalmars-d mailing list