Checking if a type is void
Stefan Koch
uplink.coder at googlemail.com
Sat May 28 14:20:22 UTC 2022
Good Day everyone, I know it has been a while since I last posted
on here.
Did you know that you could check if a type is void without
having to mention the type void?
And you do it like this
```D
template isVoid(alias X)
{
enum bool isVoid = is(mixin(`!X`));
}
pragma(msg, isVoid!(int));
```
Check it out for yourself ;)
The reason this is that internally a TypeExpression is created
and all Expressions defined a `!` operation.
Because all of them are values/ do have init-expressions.
Except for the one type that doesn't which is void.
Which is why you cannot create an init expression for void, and
that makes the expression `!void` fail during the semantic checks.
Cheers,
Stefan
More information about the Digitalmars-d
mailing list