diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..674da793 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Avoids changelog conflicts by assuming additions-only, which is by far the common case. +# In the rare case where branch b1 rebases against branch b2 and both branches +# modified the same changelog entry, you'll end up with that changelog entry +# duplicated, which is easily identifiable and fixable. +/changelog.md merge=union + diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..5c2e7664 --- /dev/null +++ b/changelog.md @@ -0,0 +1,3 @@ +## additions and changes + +- Added module `pointers` containing `toUncheckedArray` diff --git a/src/fusion/pointers.nim b/src/fusion/pointers.nim new file mode 100644 index 00000000..4c92f74b --- /dev/null +++ b/src/fusion/pointers.nim @@ -0,0 +1,17 @@ +##[ +Convenience procs to deal with pointer-like variables. +]## + +proc toUncheckedArray*[T](a: ptr T): ptr UncheckedArray[T] {.inline.} = + ## Shortcut for `cast[ptr UncheckedArray[T]](a)`, where T is inferred. + ## This allows array indexing operations on `a`. + ## This is unsafe as it returns `UncheckedArray`. + runnableExamples: + var a = @[10, 11, 12] + let pa = a[1].addr.toUncheckedArray + doAssert pa[-1] == 10 + pa[0] = 100 + doAssert a == @[10, 100, 12] + pa[0] += 5 + doAssert a[1] == 105 + cast[ptr UncheckedArray[T]](a)