Find in assoc array then iterate
Ali Çehreli
acehreli at yahoo.com
Sat Oct 22 22:17:46 UTC 2022
On 10/22/22 08:21, Kevin Bailey wrote:
> his claim that there was no value.
I think he was questioning the need for iterating from a point forward
inside an unordered container. When the container is unordered, the
elements that are accessed after a found element could be anything. I
think that's the puzzling part in your question.
> package main
Here is my interpretation of Paul Backus's solution:
module main;
import std.stdio;
void main() {
int[string] m;
m["key1"] = 7;
m["key2"] = 8;
auto iter = m.byKeyValue();
// Advance iterator
iter.popFront();
// Preserve position
auto iter2 = iter.save();
// Exhaust first iterator
foreach (kv; iter) {
writeln("iter: ", kv.key, " = ", kv.value);
}
// What does second iterator see?
foreach (kv; iter2) {
writeln("iter2: ", kv.key, " = ", kv.value);
}
}
May print (because its unordered):
iter: key2 = 8
iter2: key2 = 8
Ali
More information about the Digitalmars-d-learn
mailing list