Re: How to check if variable of some type can be of null value?

2021-07-25 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 24 July 2021 at 18:10:07 UTC, Alexey wrote: The goal I with to achieve by this check - is to use template and to assign value to variable basing on it's ability to accept null as a value. The most direct representation of that is __traits(compiles, (T t) { t = null; });

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 20:10:37 UTC, JG wrote: On Saturday, 24 July 2021 at 19:39:02 UTC, Alexey wrote: [...] There are probably better ways. However, this seems to work: ```d import std; enum canBeSetToNull(T) = __traits(compiles,(T.init is null)); interface I1 { } class C1 : I1 { }

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 19:39:02 UTC, Alexey wrote: On Saturday, 24 July 2021 at 18:10:07 UTC, Alexey wrote: I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread Alexey via Digitalmars-d-learn
On Saturday, 24 July 2021 at 18:10:07 UTC, Alexey wrote: I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is to use template and to assign value to variable basing on

How to check if variable of some type can be of null value?

2021-07-24 Thread Alexey via Digitalmars-d-learn
I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is to use template and to assign value to variable basing on it's ability to accept null as a value. some testing