Skip to content

Instantly share code, notes, and snippets.

@Vindaar
Created May 28, 2018 08:04
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 Vindaar/221abd45f59c00b515bc3cc9d9ae59e7 to your computer and use it in GitHub Desktop.
Save Vindaar/221abd45f59c00b515bc3cc9d9ae59e7 to your computer and use it in GitHub Desktop.
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