Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## additions and changes

- Added module `pointers` containing `toUncheckedArray`
17 changes: 17 additions & 0 deletions src/fusion/pointers.nim
Original file line number Diff line number Diff line change
@@ -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)