www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Multidimensional Box arrays

reply Myron Alexander <someone somewhere.com> writes:
Hello.

How does one create multidimensional Box arrays?

I'm looking to be able to do this:

Box[] a = boxArray(25, "Hello World", 1337);
Box[] b = boxArray("X", "Y", 42);

Box[][] ab = [a,b];

Then:

unbox!(int)(ab[0][0])

Thanks,

Myron.
Feb 02 2007
parent Myron Alexander <someone not_an_email_address.com> writes:
Hello.

I seem to have solved my problem. I'm not sure what I am doing differently but
it seems to work now :)

----------
import std.stdio;
import std.boxer;

void main() {
	writefln ("Boxing day");

	Box[] a = boxArray(25, "Hello World", 1337);
	Box[] b = boxArray("X", "Y", 42);

	Box[][] ab = [a,b];

	writefln ("%d, %s, %d", unbox!(int)(ab[0][0]), unbox!(char[])(ab[0][1]),
unbox!(int)(ab[0][2]));
	writefln ("%s, %s, %d", unbox!(char[])(ab[1][0]), unbox!(char[])(ab[1][1]),
unbox!(int)(ab[1][2]));
}
----------

Regards,

Myron
Feb 02 2007