Re: How to check if something can be null

2022-07-01 Thread Antonio via Digitalmars-d-learn
On Friday, 1 July 2022 at 15:35:00 UTC, Adam D Ruppe wrote: On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote: I has been using this pattern each time something needs special treatment when it can be null: i'd prolly check `static if(is(typeof(null) : T))` which means if the null literal

Re: How to check if something can be null

2022-07-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote: I has been using this pattern each time something needs special treatment when it can be null: i'd prolly check `static if(is(typeof(null) : T))` which means if the null literal implicitly converts to type T. there's also the bludgeon

Re: How to check if something can be null

2022-07-01 Thread user1234 via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:53:28 UTC, Antonio wrote: On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote: -Why? I realized Json is an struct (not an object)... and I supose, it is managing null asignation manually (as a way to build Json(null)). -Whats the correct whay to test if

Re: How to check if something can be null

2022-07-01 Thread Antonio via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote: -Why? I realized Json is an struct (not an object)... and I supose, it is managing null asignation manually (as a way to build Json(null)). -Whats the correct whay to test if something can be null? That's my question :-p

How to check if something can be null

2022-07-01 Thread Antonio via Digitalmars-d-learn
I has been using this pattern each time something needs special treatment when it can be null: ```d void doSomething(T)(T v) { import std.traits: isAssignable; static if( isAssignable!(T, typeof(null))) { if(v is null) writeln("This is null"); else writeln("This is not