array cast should be supported corrected

Frank Benoit keinfarbton at googlemail.com
Wed Aug 6 12:07:38 PDT 2008


interface I{}
class C : I {}

C[] carray = getInstance();
I[] iarray = carray; // compile error
I[] iarray = cast(I[])carray; // runtime error (1)

// correct way:
I[] iarray = new I[carray.length];
foreach( idx, c; carray ){
	iarray[idx] = c; // implicit cast
}

I use a template for doing this, but this looks so ugly.
I[] iarray = arraycast!(I)(carray);

I think the D compiler should call a runtime method in (1) to do the 
cast in a loop, instead of doing a simple type change that is not 
working correctly.






More information about the Digitalmars-d mailing list