Add cursor to lists iterator variables (#22531)

* followup #21507
This commit is contained in:
Amjad Ben Hedhili
2023-08-24 19:57:49 +01:00
committed by GitHub
parent 1013378854
commit fc6a388780

View File

@@ -286,7 +286,7 @@ iterator nodes*[T](L: SomeLinkedList[T]): SomeLinkedNode[T] =
x.value = 5 * x.value - 1
assert $a == "[49, 99, 199, 249]"
var it = L.head
var it {.cursor.} = L.head
while it != nil:
let nxt = it.next
yield it
@@ -311,7 +311,7 @@ iterator nodes*[T](L: SomeLinkedRing[T]): SomeLinkedNode[T] =
x.value = 5 * x.value - 1
assert $a == "[49, 99, 199, 249]"
var it = L.head
var it {.cursor.} = L.head
if it != nil:
while true:
let nxt = it.next
@@ -733,7 +733,7 @@ proc remove*[T](L: var SinglyLinkedList[T], n: SinglyLinkedNode[T]): bool {.disc
if L.tail.next == n:
L.tail.next = L.head # restore cycle
else:
var prev = L.head
var prev {.cursor.} = L.head
while prev.next != n and prev.next != nil:
prev = prev.next
if prev.next == nil: