D,
pasted
on Dec 29:
|
|
import std.stdio, std.string;
struct Foo {
int something;
char[] toString() { return format("%s", something); }
}
Foo[] test = cast(Foo[])([1, 2, 3, 4]);
static x = [1, 2, 3, 4];
static x2 = [1.34, 6.45, 12.3];
void main() {
writefln("%s", test);
writefln("%s", cast(Foo[])(x));
//and this made many people believe that casting arrays does the right thing:
writefln("%s", cast(int[])([1.34, 6.45, 12.3]));
//but it doesn't work
writefln("%s", cast(int[])x2);
}
|
Output:
|
|
[0,0,0,0]
[1,2,3,4]
[1,6,12]
[-687194767,1073049763,-858993459,1075432652,-1717986918,1076402585]
|
|