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

Paul Backus snarwin at gmail.com
Fri Feb 26 05:34:26 UTC 2021


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?

Something like this should work:

enum isAssignableNull(T) = __traits(compiles, (T t) => t = null);


More information about the Digitalmars-d-learn mailing list