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

Mr. Anonymous mailnew4ster at gmail.com
Thu Jul 4 09:58:09 PDT 2013


On Thursday, 4 July 2013 at 12:52:14 UTC, Regan Heath wrote:
> Whether there is an allocation or not is secondary.  The 
> primary goal is for [] to represent empty, not null.  We have 
> null, if we want to represent null we pass null.  What we lack 
> is a way to represent empty.
>
> So, I would say that what [] returns should be empty, and not 
> null.
>
> Secondarily we want to avoid allocation, so .. can we not have 
> [] return a slice of length 0 with ptr set to a global 
> pre-allocated single byte of memory?
>
> R

Here's C++'s way of handling it (note the "unique"):
--quoting--
There is a special case for a zero-length array (N == 0). In that 
case, array.begin() == array.end(), which is some unique value. 
The effect of calling front() or back() on a zero-sized array is 
undefined.
--/quoting--
http://en.cppreference.com/w/cpp/container/array


More information about the Digitalmars-d mailing list