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:
Yuriy Glukhov 2018-07-20 10:43:46 +03:00 committed by GitHub
commit 55cb45a9ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -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)

View File

@ -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]"