I have been playing with the matrix example given at the end of
chapter 78 of Ali Çehreli's fabulous book and am having problems
with overloading the opAssign operator.
rows is a private int[][] in a Matrix struct.
I have added the following ...
Matrix opAssign(int[][] arr)
{
this.rows = arr;
// rows = arr // does not work either ...
return this;
}
However this does not work (no error occurs, it just doesn't do
anything) but this does work ...
Matrix opAssign(int[][] arr)
{
foreach(i, row; rows){
row[] = arr[i];
}
return this;
}
The second is not efficient since it has to loop to assign the
array. Is there a more efficient way of overwriting the array?