Merge pull request #7 from jangko/equality_operator
fixes #6, add equality operator
This commit is contained in:
commit
a9f253b8a4
|
@ -66,6 +66,10 @@ proc `[]`*[T](r: Range[T], idx: int): T {.inline.} =
|
||||||
assert(idx < r.len)
|
assert(idx < r.len)
|
||||||
r.start.shift(idx)[]
|
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) =
|
iterator ptrs[T](r: Range[T]): (int, ptr T) =
|
||||||
var p = r.start
|
var p = r.start
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
|
@ -19,3 +19,10 @@ suite "Typed ranges":
|
||||||
let b = toRange(@[1, 2, 3])
|
let b = toRange(@[1, 2, 3])
|
||||||
a[1 .. 3] = b
|
a[1 .. 3] = b
|
||||||
check a.toSeq == @[0, 1, 2, 3, 0]
|
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
|
||||||
|
|
Loading…
Reference in New Issue