Created
February 15, 2015 09:50
-
-
Save Deco/b2b5c4310e0d7164e614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{.experimental.} | |
type Mat2F | |
[ | |
rowCount, colCount: static[int]; | |
elementType | |
] = | |
object ## A 2-dimensional fixed-sized matrix of an arbitrary type | |
elementList: array[rowCount*colCount, elementType] | |
template mat2F*( | |
rowCount, colCount: static[int]; | |
elementType: typedesc = float64 | |
): auto = | |
var result : Mat2F[rowCount, colCount, elementType] | |
result | |
proc `[]`*[ | |
rowCount, colCount: static[int]; | |
elementType | |
]( | |
mat: Mat2F[rowCount, colCount, elementType]; # Error: internal error: cannot generate code for: rowCount | |
rowI, colI: int | |
): elementType = | |
assert rowI >= 0 and rowI < rowCount | |
assert colI >= 0 and colI < colCount | |
mat.elementList[rowI*colCount + colI] | |
var a = mat2F(3, 3) | |
echo "#### ", a.elementList[0] # works | |
echo "#### ", a[0,0] # Info: instantiation from here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment