mirror of
https://github.com/status-im/nim-stew.git
synced 2025-02-13 12:36:57 +00:00
Add array.countof and openarray.toArray
This commit is contained in:
parent
3fce87f0f5
commit
f08d65b298
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user