Array Appenders
Denis Koroskin
2korden at gmail.com
Wed Apr 8 04:41:41 PDT 2009
On Wed, 08 Apr 2009 15:04:29 +0400, Frits van Bommel <fvbommel at remwovexcapss.nl> wrote:
> Andrei Alexandrescu wrote:
>> Denis Koroskin wrote:
>>> Well, actually I think that having an Appender object is an overkill.
>>> I never use, although I wrote a few implementations. Instead, I found
>>> the following method to be extemely handy, very fast and cover all my
>>> cases:
>>>
>>> void append(T)(T[] array, ref size_t index, T value)
>>> {
>>> assert(array.length >= index);
>>> if (array.length == index) {
>>> array.length = array.length * 2;
>>> }
>>> array[index++] = value;
>>> }
>> I'm pretty sure you meant to pass array by reference.
>
> It also breaks when the array is empty.
Yeah, I was writing from memory and could (and did!) introduce bugs.
My intend was to show an easy way of appending to array without use of a special Appender struct. I use it /very/ often and believe it belongs to std.array.
More information about the Digitalmars-d
mailing list