how do you append arrays?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 25 11:12:08 PST 2016
On 2/25/16 8:24 AM, asdf wrote:
> On Thursday, 25 February 2016 at 13:06:10 UTC, cym13 wrote:
>>>
>>> In D the binary operator "~" is used to concatenate both strings
>>> (arrays of characters) and arrays. (also the ~= operator is
>>> equivalent to lhs = lhs ~ rhs
>>>
>>> Nic
>>
>> Just a precision: "lhs ~= rhs" isn't exactly equivalent to "lhs = lhs
>> ~ rhs", those are two distinct operators that may deal with memory etc
>> in different ways. For arrays doing "lhs = lhs ~ rhs" will first
>> create (and allocate) the array corresponding to "lhs ~ rhs" and then
>> assign this new array to lhs. On the other hand "lhs ~= rhs" realises
>> in-place append.
>
> I tried both, the error this time is:
> object.Exception@/data/data/com.termux/files/home/ldc/runtime/druntime/src/ldc/arrayinit.d(151):
> overlapping array copy
overlapping copies are not supported.
In this case especially, the copying has to be done backwards.
I believe you could use std.algorithm.copy, but probably need to do it
with retro as well.
-Steve
More information about the Digitalmars-d-learn
mailing list