Copying with immutable arrays

Tobias Pankrath tobias at pankrath.net
Sat Oct 27 02:30:37 PDT 2012


So I have this immutable array with user defined structs but I 
can not
make a copy from it.

See:

struct SwA {
     string[] strings;
}

void main()
{
     immutable(SwA)[] arr1;
     SwA[] arr2 = arr1.dup;
}

Says:
Error: cannot implicitly convert element type immutable(SwA) to 
mutable in arr1.dup

Next try:

struct SwA {
     string[] strings;
}

void main()
{
     import std.algorithm;
     immutable(SwA)[] arr1;
     SwA[] arr2;
     copy(arr1, arr2);
}

Says:
test.d(11): Error: template std.algorithm.copy does not match any 
function template declaration
/home/tobias/projekte/d/dmd/src/../../phobos/std/algorithm.d(5859): 
Error: template std.algorithm.copy(Range1,Range2) if 
(isInputRange!(Range1) && 
isOutputRange!(Range2,ElementType!(Range1))) cannot deduce 
template function from argument types !()(immutable(SwA)[],SwA[])

(Which is a bug, I guess).

So can I do this without a cast?


More information about the Digitalmars-d-learn mailing list