How do I check if a type is assignable to null at compile time?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Feb 27 01:23:06 UTC 2021


On Sat, Feb 27, 2021 at 01:03:56AM +0000, Jack via Digitalmars-d-learn wrote:
> On Friday, 26 February 2021 at 23:37:18 UTC, Murilo wrote:
> > On Friday, 26 February 2021 at 05:25:14 UTC, Jack wrote:
> > > I started with:
> > > 
> > > enum isAssignableNull(T) = is(T : Object) || isPointer(T);
> > > 
> > > but how do I cover all cases?
> > 
> > You can check if it's null with this `variable is null` and you
> > can test it with assert as in `assert(variable is null);`
> 
> I mean a give type T not variablee

Why not just:

	enum isAssignableNull(T) = is(typeof((T t){ t = null; }));

?


T

-- 
What are you when you run out of Monet? Baroque.


More information about the Digitalmars-d-learn mailing list