Difficulty copying multi dimensional static array to dynamic array.
Derek Parnell
derek at nomail.afraid.org
Mon Feb 25 15:40:25 PST 2008
On Tue, 26 Feb 2008 09:39:49 +1100, Derek Parnell wrote:
> On Mon, 25 Feb 2008 23:11:11 +0100, Saaa wrote:
>
>> Using ref should do the trick without pointers.
Oh and if it's "tricks" you want ;-) this works ...
import std.stdio;
struct nastytrick(T)
{
T m;
}
alias float[3][5] a2D;
alias nastytrick!(a2D) sa2D;
void fillArray(ref sa2D data)
{
invariant int maxi = data.m.length;
invariant int maxj = data.m[0].length;
for (int i = 0; i < maxi; i++)
for (int j = 0; j < maxj; j++)
data.m[i][j] = i*maxj + j;
}
void main()
{
sa2D x; // declare static array inside its struct wrapper.
fillArray( x );
std.stdio.writefln("%s", x.m);
}
It seems very odd that a struct can be passed using 'ref' but a fixed
length array can't be.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
26/02/2008 10:27:35 AM
More information about the Digitalmars-d-learn
mailing list