Merge pull request #7 from jangko/equality_operator

fixes #6,  add equality operator
This commit is contained in:
Yuriy Glukhov 2018-06-06 20:07:58 +03:00 committed by GitHub
commit a9f253b8a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -66,6 +66,10 @@ proc `[]`*[T](r: Range[T], idx: int): T {.inline.} =
assert(idx < r.len)
r.start.shift(idx)[]
proc `==`*[T](a, b: Range[T]): bool =
if a.len != b.len: return false
equalMem(a.start, b.start, sizeof(T) * a.len)
iterator ptrs[T](r: Range[T]): (int, ptr T) =
var p = r.start
var i = 0

View File

@ -19,3 +19,10 @@ suite "Typed ranges":
let b = toRange(@[1, 2, 3])
a[1 .. 3] = b
check a.toSeq == @[0, 1, 2, 3, 0]
test "equality operator":
var x = toRange(@[0, 1, 2, 3, 4, 5])
var y = x[1 .. ^2]
var z = toRange(@[1, 2, 3, 4])
check y == z
check x != z