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):
|
when not declared(default):
|
||||||
proc default*(T: type): T = discard
|
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…
Reference in New Issue