Why does this code only work with `T` and not `typeof(T)`?
thebluepandabear
therealbluepandabear at protonmail.com
Wed Jan 4 04:55:59 UTC 2023
On Wednesday, 4 January 2023 at 04:42:08 UTC, Ali Çehreli wrote:
> 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
Ok, that makes sense now, my mistake. I seem to have gotten the
wrong impression that typeof is more flexible than it is.
More information about the Digitalmars-d-learn
mailing list