mirror of
https://github.com/status-im/nim-ranges.git
synced 2025-01-13 14:25:36 +00:00
add pointer distance function
This commit is contained in:
parent
f776d57b3e
commit
b11110240f
@ -3,5 +3,8 @@ proc baseAddr*[T](x: openarray[T]): pointer = cast[pointer](x)
|
|||||||
proc shift*(p: pointer, delta: int): pointer {.inline.} =
|
proc shift*(p: pointer, delta: int): pointer {.inline.} =
|
||||||
cast[pointer](cast[int](p) + delta)
|
cast[pointer](cast[int](p) + delta)
|
||||||
|
|
||||||
|
proc distance*(a, b: pointer): int {.inline.} =
|
||||||
|
cast[int](b) - cast[int](a)
|
||||||
|
|
||||||
proc shift*[T](p: ptr T, delta: int): ptr T {.inline.} =
|
proc shift*[T](p: ptr T, delta: int): ptr T {.inline.} =
|
||||||
cast[ptr T](shift(cast[pointer](p), delta * sizeof(T)))
|
cast[ptr T](shift(cast[pointer](p), delta * sizeof(T)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user