Hi,

I'd like to understand how array concatenation works internally, like the example below:

//DMD64 D Compiler 2.072.2
import std.stdio;
void main(){
    string[] arr;
    arr.length = 2;
    arr[0] = "Hello";
    arr[1] = "World";
    writeln(arr.length);
    arr = arr[0..1] ~ "New String" ~ arr[1..2];
    writeln(arr.length);
    foreach(string a; arr){
        writeln(a);
    }
}
http://rextester.com/DDW84343

The code above prints:
2
3
Hello
New String
World


So, It changes the "arr" length and put the "New String" between the other two. It's very fast with some other tests that I made.

Now I'm curious to know what's happening under the hood. It's related to memcpy?

On Phobos "array.d" source I've found this:

    /// Concatenation with rebinding.
    void opCatAssign(R)(R another)
    {
        auto newThis = this ~ another;
        move(newThis, this);
    }

But now I'm having problem to find how I can reach this "move" function, since I couldn't find any "move" on the "std" folder.

Thanks in advance.

Reply via email to