Merge pull request #3215 from rbehrends/fix-reversed-empty

Fixed algorithm.reversed to work for empty seq's.
This commit is contained in:
Andreas Rumpf 2015-08-21 17:06:30 +02:00
commit e4c164144d

View file

@ -48,8 +48,9 @@ proc reverse*[T](a: var openArray[T]) =
## reverses the array `a`. ## reverses the array `a`.
reverse(a, 0, a.high) reverse(a, 0, a.high)
proc reversed*[T](a: openArray[T], first, last: Natural): seq[T] = proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T] =
## returns the reverse of the array `a[first..last]`. ## returns the reverse of the array `a[first..last]`.
assert last >= first-1
var i = last - first var i = last - first
var x = first.int var x = first.int
result = newSeq[T](i + 1) result = newSeq[T](i + 1)