how do you append arrays?

asdf via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 25 05:24:09 PST 2016


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


More information about the Digitalmars-d-learn mailing list