diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-05-03 23:43:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 23:43:41 +0200 |
commit | 9c3e23e0751881b16fab813fd3c2edc1b98b7f68 (patch) | |
tree | 004e8531a6ca96aa4ffb37f7c25013e991e0a58f | |
parent | 515ab81477c1c3e4811c4fbf43a3ff81b87be970 (diff) | |
download | Nim-9c3e23e0751881b16fab813fd3c2edc1b98b7f68.tar.gz |
Fix ..< iterator (#11103)
* add iterator overloads * add test
-rw-r--r-- | lib/system.nim | 14 | ||||
-rw-r--r-- | tests/iter/tcountup.nim | 20 |
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim index bf2e156b4..b13419eb9 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2641,6 +2641,20 @@ when defined(nimNewRoof): yield i inc i + template dotdotLessImpl(t) {.dirty.} = + iterator `..<`*(a, b: t): t {.inline.} = + ## A type specialized version of ``..<`` for convenience so that + ## mixing integer types works better. + var res = a + while res < b: + yield res + inc(res) + + dotdotLessImpl(int64) + dotdotLessImpl(int32) + dotdotLessImpl(uint64) + dotdotLessImpl(uint32) + else: iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} = ## Counts from ordinal value `a` up to `b` (inclusive) with the given diff --git a/tests/iter/tcountup.nim b/tests/iter/tcountup.nim index f93f1536e..5f75e653c 100644 --- a/tests/iter/tcountup.nim +++ b/tests/iter/tcountup.nim @@ -1,9 +1,25 @@ discard """ - output: "0123456789" + output: ''' +0123456789 +0.0 +''' """ # Test new countup for i in 0 ..< 10'i64: stdout.write(i) -echo "\n" + +echo() + +# 11099 + +var + x: uint32 + y: float + +for i in 0 ..< x: + if i == 1: echo i + y += 1 + +echo y |