diff options
author | kitty piapiac <kcp@bsd.computer> | 2020-07-29 10:30:06 -0700 |
---|---|---|
committer | kitty piapiac <kcp@bsd.computer> | 2020-07-29 10:30:06 -0700 |
commit | 970d1279c082c8d9e7a6bde32644a32322e2e0d2 (patch) | |
tree | 67a85ea89ec3e8493dec3ffc690a83de6ee3c356 /src/ptrmath.nim | |
parent | e95ea8a8535f05f7647e86af6a7fc326c3bda3af (diff) |
彡゚◉ω◉ )つー☆* MATHS
TILE
Diffstat (limited to 'src/ptrmath.nim')
-rw-r--r-- | src/ptrmath.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ptrmath.nim b/src/ptrmath.nim new file mode 100644 index 0000000..7de2fa6 --- /dev/null +++ b/src/ptrmath.nim @@ -0,0 +1,19 @@ +# from http://forum.nim-lang.org/t/1188#7366 + +template `+`*[T](p: ptr T, off: int): ptr T = + cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[])) + +template `+=`*[T](p: ptr T, off: int) = + p = p + off + +template `-`*[T](p: ptr T, off: int): ptr T = + cast[ptr type(p[])](cast[ByteAddress](p) -% off * sizeof(p[])) + +template `-=`*[T](p: ptr T, off: int) = + p = p - off + +template `[]`*[T](p: ptr T, off: int): T = + (p + off)[] + +template `[]=`*[T](p: ptr T, off: int, val: T) = + (p + off)[] = val
\ No newline at end of file |