Add array.countof and openarray.toArray

This commit is contained in:
Zahary Karadjov 2019-07-24 13:39:34 +03:00
parent 3fce87f0f5
commit f08d65b298
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 7 additions and 0 deletions

View File

@ -17,3 +17,10 @@ template init*(lvalue: var auto, a1, a2, a3: auto) =
when not declared(default):
proc default*(T: type): T = discard
template countof*[R, T](v: array[R, T]): int =
sizeof(v) div sizeof(T)
proc toArray*[T](N: static int, data: openarray[T]): array[N, T] =
doAssert data.len == N
copyMem(addr result[0], unsafeAddr data[0], N)