Skip to content

Commit 32289fa

Browse files
committed
new pointers.toUncheckedArray
1 parent 4e438f9 commit 32289fa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
- Added `progressInterval` argument to `asyncftpclient.newAsyncFtpClient` to control the interval
213213
at which progress callbacks are called.
214214

215+
- Added module `pointers` containing `toUncheckedArray`
215216

216217
## Language changes
217218

lib/std/pointers.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##[
2+
Convenience procs to deal with pointer-like variables.
3+
]##
4+
5+
proc toUncheckedArray*[T](a: ptr[T]): ptr UncheckedArray[T] {.inline.} =
6+
## calls `cast[ptr UncheckedArray[T]]` (less error prone).
7+
runnableExamples:
8+
var a = @[10, 11, 12]
9+
let pa = a[1].addr.toUncheckedArray
10+
doAssert pa[-1] == 10
11+
pa[0] = 100
12+
doAssert a == @[10, 100, 12]
13+
pa[0] += 5
14+
doAssert a[1] == 105
15+
cast[ptr UncheckedArray[T]](a)

0 commit comments

Comments
 (0)