Hi
I have been wondering why _`..`_ operator works only for _countup_. Why there
is no counterpart for _couontdown_?
For instance something like:
when sizeof(int) <= 2:
type IntLikeForCount = int|int8|int16|char|bool|uint8|enum
else:
type IntLikeForCount = int|int8|int16|int32|char|bool|uint8|uint16|enum
iterator `..`[S, T](a: S, b: T): T {.inline.} =
dbg("Using .. for ", a, ", ", b)
if a > b:
when T is IntLikeForCount:
var res = int(a)
while res >= int(b):
yield T(res)
dec(res, 1)
else:
var res = a
while res >= b:
yield res
dec(res, 1)
else:
when T is IntLikeForCount:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res)
else:
var res: T = T(a)
while res <= b:
yield res
inc(res)
Perhaps it is naive approach but I assume that it could be written to resemble
currently existing _`..`_ implementation.