Nim
Nim copied to clipboard
testBit should work with BackwardsIndex
Summary
testBit in std/bitops should be able to accept an index from the end of a type.
Description
To get the msb bit of an integer, you currently have to do something like:
testBit(x, BitsRange[typeof x].high)
or
testBit(x, sizeof(x)*8-1)
It would be nicer if this could be simply testBit(x, ^1)
Note that a naive implementation would be slightly less than ideal since, unlike range, BackwardsIndex is not bounds-checked at compile time. E.g. [0,1,2][5] fails at compile time but [0,1,2][^4] fails at runtime.
Alternatives
No response
Standard Output Examples
No response
Backwards Compatibility
No response
Links
No response