resizeable arrays: T[new]
Walter Bright
newshound1 at digitalmars.com
Mon Jun 4 10:45:09 PDT 2007
Oskar Linde wrote:
> Walter Bright wrote:
>
>> Now, it turns out that it is very rare for a function to legitimately
>> want to resize a buffer passed to it. So we finally hit on the idea of
>> making a resizeable array a different type, say:
>
> An excellent suggestion. And I'm not only saying that because I have
> suggested this several times myself. :p
Can you point me to the posting(s)? You should get the credit for being
first.
>>
>> T[n] a; // static array
>> T[] b; // dynamic array
>> T[new] c; // resizeable array
>
> I'd propose a different nomenclature:
>
> T[n] a; // static array
> T[] b; // (array) slice
> T[new] c; // dynamic array
I like "resizeable" array because it is pretty clear what it does.
> I also agree with others that there are better alternatives to "new".
> T[*] is my favorite.
Looks like C99's VLA.
> Short version: You always want to pass ref T[new]. Forgetting ref is
> probably a bug, but is silently accepted by the compiler. Ergo, ref
> should be the default. :)
Frits has posted a realistic use case that argues it shouldn't be.
More information about the Digitalmars-d-announce
mailing list