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

Nathan S. no.public.email at example.com
Fri Feb 26 05:45:39 UTC 2021


On Friday, 26 February 2021 at 05:34:26 UTC, Paul Backus 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?
>
> Something like this should work:
>
> enum isAssignableNull(T) = __traits(compiles, (T t) => t = 
> null);

`isAssignableNull!(immutable void*)` is true with his definition 
but false with yours. Of course you are correct that you cannot 
assign to an immutable pointer.


More information about the Digitalmars-d-learn mailing list