diff options
Diffstat (limited to 'lib/system/indices.nim')
-rw-r--r-- | lib/system/indices.nim | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/system/indices.nim b/lib/system/indices.nim index fb6151a74..f2bad2528 100644 --- a/lib/system/indices.nim +++ b/lib/system/indices.nim @@ -110,13 +110,13 @@ proc `[]`*[Idx, T; U, V: Ordinal](a: array[Idx, T], x: HSlice[U, V]): seq[T] {.s ## var a = [1, 2, 3, 4] ## assert a[0..2] == @[1, 2, 3] ## ``` + ## + ## See also: + ## * `toOpenArray(array[I, T];I,I) <#toOpenArray,array[I,T],I,I>`_ let xa = a ^^ x.a let L = (a ^^ x.b) - xa + 1 - # Workaround bug #22852: - result = newSeq[T](if L < 0: 0 else: L) + result = newSeq[T](L) for i in 0..<L: result[i] = a[Idx(i + xa)] - # Workaround bug #22852 - discard Natural(L) proc `[]=`*[Idx, T; U, V: Ordinal](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]) {.systemRaisesDefect.} = ## Slice assignment for arrays. @@ -139,6 +139,9 @@ proc `[]`*[T; U, V: Ordinal](s: openArray[T], x: HSlice[U, V]): seq[T] {.systemR ## var s = @[1, 2, 3, 4] ## assert s[0..2] == @[1, 2, 3] ## ``` + ## + ## See also: + ## * `toOpenArray(openArray[T];int,int) <#toOpenArray,openArray[T],int,int>`_ let a = s ^^ x.a let L = (s ^^ x.b) - a + 1 newSeq(result, L) |