Thank you for your detailed answer!

What I don't understand is the reason why you need the .dup in the first place.

Take a look at these two structs that now contain an int* and an int instead of string[].

struct SA {
    int i;
}

struct SB {
    int* i;
}

If you try to .dup an array of SA it will work and if you .dup an array of SB it will fail. I understand why it works this way, because in case of SB you would get an mutable reference of type int* out of immutable(int*), which would brake the type system. However the struct SwA from above does neither correspond to SA nor to SB, it's imo more like SC:

struct SC {
    immutable(int)* i;
}

Now a copy would do no harm, everything that was immutable in the source and is still accessable from the copy is immutable, too. Any reason (despite of implemenational issues) that this is not how it works?


Reply via email to