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

Reply via email to