What is the difference between a[x][y] and a[x,y]?
Adam D. Ruppe
destructionator at gmail.com
Tue Jan 7 17:42:48 UTC 2020
On Tuesday, 7 January 2020 at 17:38:59 UTC, Robert M. Münch wrote:
> I read all the docs but I'm not toally sure. Is it that [x][y]
> is a 2D array-index, where as [x,y] is a slice?
So [x][y] indexes an array of arrays. [x,y] indexes a single
array that has two dimensions.
This can be kinda confusing because we often think of
int[4][4]
as being a 2d array, but the D language actually technically sees
that as an array of arrays. So it is indexed with [x][y].
There is no built in multi-dimensional array, it is only syntax
provided for library types to implement with the opIndexAssign
overloads.
> And what is the difference between opIndexAssign and
> opIndexOpAssign?
foo[5] = x; // opIndexAssign
foo[4] += x; // opIndexOpAssign
So the operator there like += or -= or *= etc become opAssign,
whereas plain = is just plain Assign.
More information about the Digitalmars-d-learn
mailing list