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

Artur Skawina art.08.09 at gmail.com
Fri Jul 5 05:26:30 PDT 2013


On 07/05/13 12:39, Dmitry Olshansky wrote:
> 05-Jul-2013 13:24, Regan Heath пишет:
>> 1. Arrays are a thin wrapper around a reference type (ptr) which add
>> safety.
> 
> Rather it packs 2 pointers (pair: ptr, ptr+len), modeling the region in between.
> No matter how we look at it, it doesn't overlap with most of pointer operations except for indexing. In my opinion it can't be framed as a thin wrapper around _one_ pointer.

The 'array' term is overloaded and confusing, let's call them "slices".

Slices are nothing but fat pointers; they just carry more information -
- the length.

>> 2. When you have a thin wrapper you should treat operations on the
>> wrapper as the wrapped object in the general case.
> 
> Continuation of the above stretch.
> To be a true wrapper it has to support only the same or subset of operations. For instance arrays have slicing operation hence it's more then that.

   ubyte* pointer = null;
   auto slice = pointer[0..42];


>> 3. if (x) should compare x to 0.
> 
> This one is consistent.

Actually, slices should implicitly convert to bool with !!length.
"Normal" pointers couldn't do that - because they had no length.

artur


More information about the Digitalmars-d mailing list