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)))
|
2019-02-22 17:51:42 +00:00
|
|
|
|
|
|
|
when (NimMajor,NimMinor,NimPatch) >= (0,19,9):
|
|
|
|
template makeOpenArray*[T](p: ptr T, len: int): auto =
|
|
|
|
toOpenArray(cast[ptr UncheckedArray[T]](p), 0, len - 1)
|
|
|
|
|
|
|
|
template makeOpenArray*(p: pointer, T: type, len: int): auto =
|
|
|
|
toOpenArray(cast[ptr UncheckedArray[T]](p), 0, len - 1)
|
|
|
|
|
|
|
|
else:
|
|
|
|
# TODO: These are fallbacks until we upgrade to 0.19.9
|
|
|
|
template makeOpenArray*(p: pointer, T: type, len: int): auto =
|
|
|
|
toOpenArray(cast[ptr array[0, T]](p)[], 0, len - 1)
|
|
|
|
|
|
|
|
template makeOpenArray*[T](p: ptr T, len: int): auto =
|
|
|
|
toOpenArray(cast[ptr array[0, T]](p)[], 0, len - 1)
|
|
|
|
|