Moved toOpenArray above its usage
This commit is contained in:
parent
86037c1d93
commit
991bdb8443
|
@ -132,10 +132,12 @@ proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: openarray[T]) =
|
||||||
else:
|
else:
|
||||||
raise newException(RangeError, "different lengths for slice assignment")
|
raise newException(RangeError, "different lengths for slice assignment")
|
||||||
|
|
||||||
|
template toOpenArray*[T](r: Range[T]): auto =
|
||||||
|
# TODO: Casting through an {.unchecked.} array would be more appropriate
|
||||||
|
# here, but currently this results in internal compiler error.
|
||||||
|
toOpenArray(cast[ptr array[10000000, T]](r.start)[], 0, r.high)
|
||||||
|
|
||||||
proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: Range[T]) {.inline.} =
|
proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: Range[T]) {.inline.} =
|
||||||
r[s] = toOpenArray(v)
|
r[s] = toOpenArray(v)
|
||||||
|
|
||||||
proc baseAddr*[T](r: Range[T]): ptr T {.inline.} = r.start
|
proc baseAddr*[T](r: Range[T]): ptr T {.inline.} = r.start
|
||||||
|
|
||||||
template toOpenArray*[T](r: Range[T]): auto =
|
|
||||||
toOpenArray(cast[ptr array[10000000, T]](r.start)[], 0, r.high)
|
|
||||||
|
|
|
@ -13,3 +13,9 @@ suite "Typed ranges":
|
||||||
var s = newSeq[int]()
|
var s = newSeq[int]()
|
||||||
for a in r: s.add(a)
|
for a in r: s.add(a)
|
||||||
check s == @[1, 2, 3, 4, 5]
|
check s == @[1, 2, 3, 4, 5]
|
||||||
|
|
||||||
|
test "subrange":
|
||||||
|
var a = newRange[int](5)
|
||||||
|
let b = toRange(@[1, 2, 3])
|
||||||
|
a[1 .. 3] = b
|
||||||
|
check a.toSeq == @[0, 1, 2, 3, 0]
|
||||||
|
|
Loading…
Reference in New Issue