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:
parent
44f672a515
commit
4e1e231e29
4 changed files with 11 additions and 11 deletions
|
|
@ -175,7 +175,7 @@ proc `[]`*(n: NimNode, i: BackwardsIndex): NimNode = n[n.len - i.int]
|
||||||
template `^^`(n: NimNode, i: untyped): untyped =
|
template `^^`(n: NimNode, i: untyped): untyped =
|
||||||
(when i is BackwardsIndex: n.len - int(i) else: int(i))
|
(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.
|
## Slice operation for NimNode.
|
||||||
## Returns a seq of child of `n` who inclusive range [n[x.a], n[x.b]].
|
## Returns a seq of child of `n` who inclusive range [n[x.a], n[x.b]].
|
||||||
let xa = n ^^ x.a
|
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): char = arrGet(s, i)
|
||||||
template `[]=`*(s: string; i: int; val: char) = arrPut(s, i, val)
|
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.
|
## Slice operation for strings.
|
||||||
## Returns the inclusive range `[s[x.a], s[x.b]]`:
|
## 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)
|
result = newString(L)
|
||||||
for i in 0 ..< L: result[i] = s[i + a]
|
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.
|
## Slice assignment for strings.
|
||||||
##
|
##
|
||||||
## If ``b.len`` is not exactly the number of elements that are referred to
|
## 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:
|
else:
|
||||||
spliceImpl(s, a, L, b)
|
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.
|
## Slice operation for arrays.
|
||||||
## Returns the inclusive range `[a[x.a], a[x.b]]`:
|
## 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)
|
result = newSeq[T](L)
|
||||||
for i in 0..<L: result[i] = a[Idx(i + xa)]
|
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.
|
## Slice assignment for arrays.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. 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:
|
else:
|
||||||
sysFatal(RangeDefect, "different lengths for slice assignment")
|
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.
|
## Slice operation for sequences.
|
||||||
## Returns the inclusive range `[s[x.a], s[x.b]]`:
|
## 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)
|
newSeq(result, L)
|
||||||
for i in 0 ..< L: result[i] = s[i + a]
|
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.
|
## Slice assignment for sequences.
|
||||||
##
|
##
|
||||||
## If ``b.len`` is not exactly the number of elements that are referred to
|
## 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):
|
for v in low(E) .. high(E):
|
||||||
yield v
|
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`
|
## Iterates over the slice `s`, yielding each value between `s.a` and `s.b`
|
||||||
## (inclusively).
|
## (inclusively).
|
||||||
for x in s.a .. s.b:
|
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
|
first type mismatch at position: 0
|
||||||
proc `[]`[I: Ordinal; T](a: T; i: I): T
|
proc `[]`[I: Ordinal; T](a: T; i: I): T
|
||||||
first type mismatch at position: 0
|
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
|
first type mismatch at position: 0
|
||||||
proc `[]`[Idx, T](a: array[Idx, T]; i: BackwardsIndex): T
|
proc `[]`[Idx, T](a: array[Idx, T]; i: BackwardsIndex): T
|
||||||
first type mismatch at position: 0
|
first type mismatch at position: 0
|
||||||
proc `[]`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex): var T
|
proc `[]`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex): var T
|
||||||
first type mismatch at position: 0
|
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
|
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
|
first type mismatch at position: 0
|
||||||
proc `[]`[T](s: openArray[T]; i: BackwardsIndex): T
|
proc `[]`[T](s: openArray[T]; i: BackwardsIndex): T
|
||||||
first type mismatch at position: 0
|
first type mismatch at position: 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue