[:] as empty associative array literal, plus warning for null

Daniel Murphy yebblies at nospamgmail.com
Fri Jul 5 06:15:35 PDT 2013


"TommiT" <tommitissari at hotmail.com> wrote in message 
news:cajkpllpdchpphqxhyer at forum.dlang.org...
> On Thursday, 4 July 2013 at 13:32:25 UTC, Steven Schveighoffer wrote:
>> On Thu, 04 Jul 2013 08:52:12 -0400, Regan Heath wrote:
>>> Indeed.  IMO if(arr) should mean if(arr.ptr) .. and I thought it did.. 
>>> or did this change at some point?
>>
>> No, it should mean if(arr.length).  It means if(arr.ptr) now, and this is 
>> incorrect.  [..]
>
> The meaning of if(x) for all x of nullable types has always been if(x != 
> null) probably in all languages.

I completely agree, these three functions should return the same no matter 
the input:
bool f(T)(T[] x) { if (x) return true; return false; }
bool g(T)(T[] x) { if (x != null) return true; return false; }
bool h(T)(T[] x) { if (x.length) return true; return false; }

The last two already do. 




More information about the Digitalmars-d mailing list