nim-ranges/ranges/ptr_arith.nim

11 lines
355 B
Nim
Raw Normal View History

2018-02-16 14:39:44 +00:00
proc baseAddr*[T](x: openarray[T]): pointer = cast[pointer](x)
2018-03-26 12:52:48 +00:00
proc shift*(p: pointer, delta: int): pointer {.inline.} =
2018-02-16 14:39:44 +00:00
cast[pointer](cast[int](p) + delta)
2018-12-17 23:01:46 +00:00
proc distance*(a, b: pointer): int {.inline.} =
cast[int](b) - cast[int](a)
2018-03-26 12:52:48 +00:00
proc shift*[T](p: ptr T, delta: int): ptr T {.inline.} =
cast[ptr T](shift(cast[pointer](p), delta * sizeof(T)))