We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
pointers
toUncheckedArray
1 parent 319aac4 commit db77aa5Copy full SHA for db77aa5
changelog.md
@@ -0,0 +1,3 @@
1
+## additions and changes
2
+
3
+- Added module `pointers` containing `toUncheckedArray`
src/fusion/pointers.nim
@@ -0,0 +1,17 @@
+##[
+Convenience procs to deal with pointer-like variables.
+]##
4
5
+proc toUncheckedArray*[T](a: ptr T): ptr UncheckedArray[T] {.inline.} =
6
+ ## Shortcut for `cast[ptr UncheckedArray[T]](a)`, where T is inferred.
7
+ ## This allows array indexing operations on `a`.
8
+ ## This is unsafe as it returns `UncheckedArray`.
9
+ runnableExamples:
10
+ var a = @[10, 11, 12]
11
+ let pa = a[1].addr.toUncheckedArray
12
+ doAssert pa[-1] == 10
13
+ pa[0] = 100
14
+ doAssert a == @[10, 100, 12]
15
+ pa[0] += 5
16
+ doAssert a[1] == 105
17
+ cast[ptr UncheckedArray[T]](a)
0 commit comments