## digitalmars.D - 2D (or higher) equivalent of ranges?

- "H. S. Teoh" <hsteoh quickfur.ath.cx> May 16 2012

Lately I've been considering how to generalize multi-dimensional arrays along the same lines as std.range. The motivation for this is that I'm designing a generic interface for manipulating n-dimensional data, and it seems too implementation- specific to impose a particular representation of an n-dimensional array (specifically, a particular ordering of dimensions, say column major or row major). I'd like to be able to take arbitrary n-dimensional slices (subarrays) of a larger array and be able to pass it to the same code as though it were an independent n-dimensional array, for example. I also want to be able to take existing data structures, say a linked list of arrays, or an array of linked lists, and be able to treat it as though it were a 2D array. Better yet, the generic code should be able to handle arrays in which some of the dimensions are infinite (e.g., a finite list of infinite ranges, or an infinite range of finite lists, or an infinite list of infinite lists -- programmatically generated, of course). Also, it should be possible to transpose the array along any pair of dimensions (e.g., traverse an array of linked-lists in breadth-first order, i.e., return the first elements of each linked list, then the second elements, etc.). How would one go about designing a generic interface that encapsulates this functionality? Is it possible with the current range definition, or is something more needed? (Note that I used 2D examples above for simplicity's sake, but this needs to handle an arbitrary number of dimensions.) Any ideas? T -- Gone Chopin. Bach in a minuet.

May 16 2012