Trouble checking for null-ness

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 25 05:47:25 PDT 2016


On Monday, 25 July 2016 at 12:37:18 UTC, Bahman Movaqar wrote:
But I'm curious; how can I check for a
> `null` in this case?

Well, if you're happy with assertion failure by access violation, 
you may not even need to check for null, because generally if you 
try to call .empty on a null pointer you'll get an access 
violation (killing two birds with one stone).

Otherwise you could try
(!__traits(compiles, r is null) || r !is null) && !r.empty


More information about the Digitalmars-d-learn mailing list