Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
type Mat2F
rowCount, colCount: static[int];
] =
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]
proc `[]`*[
rowCount, colCount: static[int];
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