breaking change: countup/'..' only take a simple generic T
This commit is contained in:
parent
617ba1a209
commit
136dbd3c6a
2 changed files with 20 additions and 1 deletions
11
changelog.md
11
changelog.md
|
|
@ -62,3 +62,14 @@ This now needs to be written as:
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
t[ti] = (if exp_negative: '-' else: '+'); inc(ti)
|
t[ti] = (if exp_negative: '-' else: '+'); inc(ti)
|
||||||
|
|
||||||
|
- To make Nim even more robust the system iterators ``..`` and ``countup``
|
||||||
|
now only accept a single generic type ``T``. This means the following code
|
||||||
|
doesn't die with an "out of range" error anymore:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
|
||||||
|
var b = 5.Natural
|
||||||
|
var a = -5
|
||||||
|
for i in a..b:
|
||||||
|
echo i
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ proc `..`*[T, U](a: T, b: U): HSlice[T, U] {.noSideEffect, inline, magic: "DotDo
|
||||||
result.b = b
|
result.b = b
|
||||||
|
|
||||||
proc `..`*[T](b: T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} =
|
proc `..`*[T](b: T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} =
|
||||||
## `slice`:idx: operator that constructs an interval ``[default(T), b]``
|
## `slice`:idx: operator that constructs an interval ``[default(int), b]``
|
||||||
result.b = b
|
result.b = b
|
||||||
|
|
||||||
when not defined(niminheritable):
|
when not defined(niminheritable):
|
||||||
|
|
@ -2014,6 +2014,14 @@ when defined(nimNewRoof):
|
||||||
while res <= b:
|
while res <= b:
|
||||||
yield res
|
yield res
|
||||||
inc(res)
|
inc(res)
|
||||||
|
|
||||||
|
iterator `..`*(a, b: int64): int64 {.inline.} =
|
||||||
|
## A special version of `..`` for ``int64`` only.
|
||||||
|
var res = a
|
||||||
|
while res <= b:
|
||||||
|
yield res
|
||||||
|
inc(res)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
|
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
|
||||||
## Counts from ordinal value `a` up to `b` (inclusive) with the given
|
## Counts from ordinal value `a` up to `b` (inclusive) with the given
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue