mirror of
https://github.com/status-im/nim-ranges.git
synced 2025-01-12 05:44:11 +00:00
Merge pull request #19 from timotheecour/pr_toOpenArray_doc
test toOpenArray and clarify doc to say 0 in cast[ptr array[0, T] is irrelevant
This commit is contained in:
commit
55cb45a9ac
@ -153,7 +153,8 @@ proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: openarray[T]) =
|
||||
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)
|
||||
# NOTE: `0` in `array[0, T]` is irrelevant
|
||||
toOpenArray(cast[ptr array[0, T]](r.start)[], 0, r.high)
|
||||
|
||||
proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: Range[T]) {.inline.} =
|
||||
r[s] = toOpenArray(v)
|
||||
|
@ -99,3 +99,6 @@ suite "Typed ranges":
|
||||
check hash(v) == hash(vv)
|
||||
check hash(uu) != hash(vv)
|
||||
|
||||
test "toOpenArray":
|
||||
var a = toRange(@[1,2,3])
|
||||
check $a.toOpenArray == "[1, 2, 3]"
|
||||
|
Loading…
x
Reference in New Issue
Block a user