www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Simulating rectangular array

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Has anyone come up with a template that can simulate a rectangular
array and allow one to override opAssign to do special work? E.g.:

Array!(2, 4) arr;
arr[1][3] = "foo";

This would invoke opAssign in some templated struct "Array". This
would be super-easy to implement if I had an opIndex that could work
with the above syntax. I know there's a "[1, 3]" syntax but I really
need the array "[1][3]" syntax.

Maybe Philippe has this in his templates book? (If not it would be a
great addition to it)
Jun 17 2012
parent Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
17.06.2012 23:50, Andrej Mitrovic пишет:
 Has anyone come up with a template that can simulate a rectangular
 array and allow one to override opAssign to do special work? E.g.:

 Array!(2, 4) arr;
 arr[1][3] = "foo";

 This would invoke opAssign in some templated struct "Array". This
 would be super-easy to implement if I had an opIndex that could work
 with the above syntax. I know there's a "[1, 3]" syntax but I really
 need the array "[1][3]" syntax.

 Maybe Philippe has this in his templates book? (If not it would be a
 great addition to it)
Full-featured, tested, multidimensional rectangular arrays with slicing support (yes, like in FORTRAN): http://deoma-cmd.ru/d/docs/src/my/rarray.html (may require all files from http://deoma-cmd.ru/d/src/my/) I really thought it's just not needed, but if it is, I will make it up-to-date with current compiler and put under version control. Original thread: http://forum.dlang.org/thread/j864es$2gi0$1 digitalmars.com -- Денис В. Шеломовский Denis V. Shelomovskij
Jun 17 2012