Created
May 28, 2018 08:04
-
-
Save Vindaar/221abd45f59c00b515bc3cc9d9ae59e7 to your computer and use it in GitHub Desktop.
This file contains 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
type | |
BitArray[T: static[int]] = array[T, '0'..'1'] | |
proc `[]=`(b: var BitArray, ind: int, val: int) = | |
b[ind] = if val == 1: '1' else: '0' | |
proc createBitarray(size: static[int]): BitArray[size] = | |
for i in 0 ..< size: | |
result[i] = '0' | |
var ba = createBitarray(48) | |
# works as expected | |
ba[32] = '1' | |
# causes compile error | |
ba[31] = 1 | |
echo ba | |
# output: | |
# bitarray_compile_error.nim(15, 8) Error: type mismatch: got <int literal(1)> but expected 'range 48..49(char)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment