std.collection lets rename it into std,ridiculous.
schveiguy at yahoo.com
Fri Feb 24 08:39:10 PST 2012
On Mon, 20 Feb 2012 11:22:32 -0500, a <a at a.com> wrote:
>> auto a = [1,2,3,4,5];
>> auto b = a[0..3];
>> b ~= 0;
>> prints [1, 2, 3, 0, 5], so b is not reallocated in this case.
> Just to clarify: this is not guaranteed to print [1, 2, 3, 0, 5], it
> only does
> if there is still enough memory in a block allocated to b and it doesn't
> to be reallocated.
In fact, it is guaranteed. a is guaranteed to be allocated on the heap,
because that's what an array literal does (currently, but it probably
shouldn't be). It's guaranteed to be inserted into a block large enough
to hold 5 numbers, so you definitely can put 4 numbers (1, 2, 3, 0) into
it. This will never reallocate.
However, It's not guaranteed that the last number will be 5 after
assumeSafeAppend is called. Once you call assumeSafeAppend, all data
after that last element is invalid (i.e. not used). To refer to that data
is implementation-defined. E.g. a different version of assumeSafeAppend
may set all invalid bytes to 0, or some other sentinel value.
More information about the Digitalmars-d