add equality operator
This commit is contained in:
parent
8b48ca4897
commit
d9e93b33a0
|
@ -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