Indexing Operators
Learn how to implement and use indexing operators in D to enable array-style access and assignment on user-defined types. Understand opIndex, opIndexAssign, opIndexUnary, opIndexOpAssign, and opDollar to handle single and multi-dimensional indexing efficiently.
We'll cover the following...
Use of indexing operators
opIndex, opIndexAssign, opIndexUnary, opIndexOpAssign, and opDollar make it possible to use indexing operators on user-defined types similar to arrays as in object[index].
Unlike arrays, these operators support multi-dimensional indexing as well. Multiple index values are specified as a comma-separated list inside the square brackets (e.g., object[index0, index1]). In the following examples, we will use these operators only with a single dimension and cover their multidimensional uses in the more ...