Why does this code only work with `T` and not `typeof(T)`?

Ali Çehreli acehreli at yahoo.com
Wed Jan 4 04:42:08 UTC 2023


On 1/3/23 20:11, thebluepandabear wrote:

 > if I replace the `isDrawable` template with the
 > following (using `typeof`), the code does not compile:

It must be because T is already a type. It's the same reason why the 
following code fails to compile:

void main() {
     alias T = int;
     alias TT = typeof(T);
}

Error: type `int` is not an expression

And the error message tells us typeof requires an expression. What you 
can do is to use T.init and the code should now work like the following 
does:

     alias TT = typeof(T.init);

Ali



More information about the Digitalmars-d-learn mailing list