Skip to content

Instantly share code, notes, and snippets.

@Deco
Created February 15, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deco/b2b5c4310e0d7164e614 to your computer and use it in GitHub Desktop.
Save Deco/b2b5c4310e0d7164e614 to your computer and use it in GitHub Desktop.
{.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