diff --git a/ranges/typedranges.nim b/ranges/typedranges.nim index 9943b69..b33cae4 100644 --- a/ranges/typedranges.nim +++ b/ranges/typedranges.nim @@ -1,4 +1,4 @@ -import ./ptr_arith +import ./ptr_arith, typetraits const rangesGCHoldEnabled = not defined(rangesDisableGCHold) const unsafeAPIEnabled = defined(rangesEnableUnsafeAPI) @@ -148,16 +148,28 @@ proc baseAddr*[T](r: Range[T]): ptr T {.inline.} = r.start template toRange*[T](a: Range[T]): Range[T] = a +# this preferred syntax doesn't work +# see https://github.com/nim-lang/Nim/issues/7995 +#template copyRange[T](dest: seq[T], destOffset: int, src: Range[T]) = +# when supportsCopyMem(T): + +template copyRange[T](E: typedesc, dest: seq[T], destOffset: int, src: Range[T]) = + when supportsCopyMem(E): + copyMem(dest[destOffset].unsafeAddr, src.start, sizeof(T) * src.len) + else: + for i in 0..