Trouble checking for null-ness

Bahman Movaqar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 25 06:09:22 PDT 2016


On 07/25/2016 05:07 PM, Bahman Movaqar wrote:
> Suppose I have the following function:
> 
>     public auto max(alias comp, Range)(Range r)
>     in {
>       assert(r !is null && !r.empty);
>     }
>     body {
>       // ...
>     }
> 
> When the function after a series of chained `map` operations, I get the
> following error:
> 
>     Error: incompatible types for ((r) !is (null)):
> 'MapResult!(__lambda2, SInvoiceLine[])' and 'typeof(null)'
> 
> Of course if I remove `r !is null` from the `in` block, everything will
> work.  But I'm curious; how can I check for a `null` in this case?

Thank you people for the answers.
>From what I could gather, it's not possible to check for `null` at
runtime for reference based types.  Am I right?

-- 
Bahman


More information about the Digitalmars-d-learn mailing list