Re: Trouble checking for null-ness

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/25/2016 05:47 PM, Adam D. Ruppe wrote: > On Monday, 25 July 2016 at 13:09:22 UTC, Bahman Movaqar wrote: >> From what I could gather, it's not possible to check for `null` at >> runtime for reference based types. Am I right? > > No, it is only possible to check for null for reference based

Re: Trouble checking for null-ness

2016-07-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 July 2016 at 13:09:22 UTC, Bahman Movaqar wrote: From what I could gather, it's not possible to check for `null` at runtime for reference based types. Am I right? No, it is only possible to check for null for reference based types. But map's result is not a reference based

Re: Trouble checking for null-ness

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
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`

Re: Trouble checking for null-ness

2016-07-25 Thread Mike Parker via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:37:18 UTC, 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,

Re: Trouble checking for null-ness

2016-07-25 Thread Cauterite via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:47:25 UTC, Cauterite wrote: (!__traits(compiles, r is null) || r !is null) && !r.empty Ah, whoops that's wrong, looks like ketmar had the right idea.

Re: Trouble checking for null-ness

2016-07-25 Thread Cauterite via Digitalmars-d-learn
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

Re: Trouble checking for null-ness

2016-07-25 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:37:18 UTC, Bahman Movaqar wrote: 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

Re: Trouble checking for null-ness

2016-07-25 Thread ketmar via Digitalmars-d-learn
static if (is(typeof(r is null))) { ...you can do your assert here... }

Trouble checking for null-ness

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
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