T[new]

Michel Fortin michel.fortin at michelf.com
Sun Aug 9 15:54:33 PDT 2009


On 2009-08-09 16:29:21 -0400, Walter Bright <newshound1 at digitalmars.com> said:

> D has a number of subtle problems (performance and semantic) that arise 
> when arrays are resized. The solution is to separate resizeable array 
> types from slices. Slices will retain the old:
> 
>     T[] slice;
> 
> syntax. Resizeable arrays will be declared as:
> 
>     T[new] array;
> 
> The new expression:
> 
>     new T[10]
> 
> will return a T[new].

I have nothing against the concept of container, but I dislike like the 
syntax. Is this really better than Array!T ?


> T[new] will implicitly convert to T[], but not the other way.
> 
> slice.length will become read-only.

All fine by me.


> Doing this change will:
> 
> 1. fix many nasties at the edges of array semantics

Unfortunatly, not all. Solving them all could be done with unique 
semantics (unique slices can be expanded with no side effect).


> 2. make arrays implementable on .net
> 
> 3. make clear in function signatures if the function can resize the 
> array or not

Unique and ref unique slices would be perfectly fine for that (assuming 
slices can be resized when unique).

But I know, unique isn't easy to implement to fit all the use cases 
we'd like to solve. I'm just sharing a dream.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list