mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 22:43:34 +00:00
fix floats slice (#16853)
* see whether it breaks * fix * fix * minor * fix * add enum * use Ordinal types * fix tests * fix * another style * fix remainning cases
This commit is contained in:
@@ -175,7 +175,7 @@ proc `[]`*(n: NimNode, i: BackwardsIndex): NimNode = n[n.len - i.int]
|
||||
template `^^`(n: NimNode, i: untyped): untyped =
|
||||
(when i is BackwardsIndex: n.len - int(i) else: int(i))
|
||||
|
||||
proc `[]`*[T, U](n: NimNode, x: HSlice[T, U]): seq[NimNode] =
|
||||
proc `[]`*[T, U: Ordinal](n: NimNode, x: HSlice[T, U]): seq[NimNode] =
|
||||
## Slice operation for NimNode.
|
||||
## Returns a seq of child of `n` who inclusive range [n[x.a], n[x.b]].
|
||||
let xa = n ^^ x.a
|
||||
|
||||
@@ -2498,7 +2498,7 @@ template `^^`(s, i: untyped): untyped =
|
||||
template `[]`*(s: string; i: int): char = arrGet(s, i)
|
||||
template `[]=`*(s: string; i: int; val: char) = arrPut(s, i, val)
|
||||
|
||||
proc `[]`*[T, U](s: string, x: HSlice[T, U]): string {.inline.} =
|
||||
proc `[]`*[T, U: Ordinal](s: string, x: HSlice[T, U]): string {.inline.} =
|
||||
## Slice operation for strings.
|
||||
## Returns the inclusive range `[s[x.a], s[x.b]]`:
|
||||
##
|
||||
@@ -2510,7 +2510,7 @@ proc `[]`*[T, U](s: string, x: HSlice[T, U]): string {.inline.} =
|
||||
result = newString(L)
|
||||
for i in 0 ..< L: result[i] = s[i + a]
|
||||
|
||||
proc `[]=`*[T, U](s: var string, x: HSlice[T, U], b: string) =
|
||||
proc `[]=`*[T, U: Ordinal](s: var string, x: HSlice[T, U], b: string) =
|
||||
## Slice assignment for strings.
|
||||
##
|
||||
## If ``b.len`` is not exactly the number of elements that are referred to
|
||||
@@ -2528,7 +2528,7 @@ proc `[]=`*[T, U](s: var string, x: HSlice[T, U], b: string) =
|
||||
else:
|
||||
spliceImpl(s, a, L, b)
|
||||
|
||||
proc `[]`*[Idx, T, U, V](a: array[Idx, T], x: HSlice[U, V]): seq[T] =
|
||||
proc `[]`*[Idx, T; U, V: Ordinal](a: array[Idx, T], x: HSlice[U, V]): seq[T] =
|
||||
## Slice operation for arrays.
|
||||
## Returns the inclusive range `[a[x.a], a[x.b]]`:
|
||||
##
|
||||
@@ -2540,7 +2540,7 @@ proc `[]`*[Idx, T, U, V](a: array[Idx, T], x: HSlice[U, V]): seq[T] =
|
||||
result = newSeq[T](L)
|
||||
for i in 0..<L: result[i] = a[Idx(i + xa)]
|
||||
|
||||
proc `[]=`*[Idx, T, U, V](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]) =
|
||||
proc `[]=`*[Idx, T; U, V: Ordinal](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]) =
|
||||
## Slice assignment for arrays.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
@@ -2554,7 +2554,7 @@ proc `[]=`*[Idx, T, U, V](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]
|
||||
else:
|
||||
sysFatal(RangeDefect, "different lengths for slice assignment")
|
||||
|
||||
proc `[]`*[T, U, V](s: openArray[T], x: HSlice[U, V]): seq[T] =
|
||||
proc `[]`*[T; U, V: Ordinal](s: openArray[T], x: HSlice[U, V]): seq[T] =
|
||||
## Slice operation for sequences.
|
||||
## Returns the inclusive range `[s[x.a], s[x.b]]`:
|
||||
##
|
||||
@@ -2566,7 +2566,7 @@ proc `[]`*[T, U, V](s: openArray[T], x: HSlice[U, V]): seq[T] =
|
||||
newSeq(result, L)
|
||||
for i in 0 ..< L: result[i] = s[i + a]
|
||||
|
||||
proc `[]=`*[T, U, V](s: var seq[T], x: HSlice[U, V], b: openArray[T]) =
|
||||
proc `[]=`*[T; U, V: Ordinal](s: var seq[T], x: HSlice[U, V], b: openArray[T]) =
|
||||
## Slice assignment for sequences.
|
||||
##
|
||||
## If ``b.len`` is not exactly the number of elements that are referred to
|
||||
|
||||
@@ -87,7 +87,7 @@ iterator items*[T: enum](E: typedesc[T]): T =
|
||||
for v in low(E) .. high(E):
|
||||
yield v
|
||||
|
||||
iterator items*[T](s: HSlice[T, T]): T =
|
||||
iterator items*[T: Ordinal](s: Slice[T]): T =
|
||||
## Iterates over the slice `s`, yielding each value between `s.a` and `s.b`
|
||||
## (inclusively).
|
||||
for x in s.a .. s.b:
|
||||
|
||||
@@ -12,15 +12,15 @@ proc `[]`(s: var string; i: BackwardsIndex): var char
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[I: Ordinal; T](a: T; i: I): T
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[Idx, T, U, V](a: array[Idx, T]; x: HSlice[U, V]): seq[T]
|
||||
proc `[]`[Idx, T; U, V: Ordinal](a: array[Idx, T]; x: HSlice[U, V]): seq[T]
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[Idx, T](a: array[Idx, T]; i: BackwardsIndex): T
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex): var T
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[T, U, V](s: openArray[T]; x: HSlice[U, V]): seq[T]
|
||||
proc `[]`[T, U: Ordinal](s: string; x: HSlice[T, U]): string
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[T, U](s: string; x: HSlice[T, U]): string
|
||||
proc `[]`[T; U, V: Ordinal](s: openArray[T]; x: HSlice[U, V]): seq[T]
|
||||
first type mismatch at position: 0
|
||||
proc `[]`[T](s: openArray[T]; i: BackwardsIndex): T
|
||||
first type mismatch at position: 0
|
||||
|
||||
Reference in New Issue
Block a user