nim-ranges/ranges/ptr_arith.nim

8 lines
276 B
Nim
Raw Normal View History

2018-02-16 16:39:44 +02:00
proc baseAddr*[T](x: openarray[T]): pointer = cast[pointer](x)
2018-03-26 15:52:48 +03:00
proc shift*(p: pointer, delta: int): pointer {.inline.} =
2018-02-16 16:39:44 +02:00
cast[pointer](cast[int](p) + delta)
2018-03-26 15:52:48 +03:00
proc shift*[T](p: ptr T, delta: int): ptr T {.inline.} =
cast[ptr T](shift(cast[pointer](p), delta * sizeof(T)))