ModularM
Modular•17mo ago•
6 replies
samufi🌳

How can I use a fixed-size integer type to index a list?

I want to use a fixed-size integer value as index of a list. However, I get the "no matching method in call to 'getitem'" error.
var l: List[Int] = List[Int]()
l.append(1)
var ind: UInt32 = 0
print(l[ind])

How can I use a 32 bit unsigned integaer such as ind in the example above as index for a list (preferably without performance penalty and lengthy additional syntax)?
Was this page helpful?