I have this struct:

struct Deb {
    string name;
    ...
    Unit[string] tags; // set of tags

    Deb copy() const {
        Deb deb;
        ...
        foreach (key, value; tags) // XXX
            deb.tags[key] = value;
        return deb;
    }

    void clear() {
        name = "";
        ...
        tags.clear;
    }

...
}

I am populating an AA with these structs:

Deb[string] debForName;

I'm using this approach (pseudo-code):

Deb deb;
foreach (datum; data) {
    populateDeb(datum, deb);
    debForName[deb.name] = deb.copy; // YYY
    deb.clear;
}

(1) XXX Is there a nicer way to copy an AA?
(2) YYY Is there a nicer way to copy a struct? Use a copy constructor or implement a dup or idup?

Reply via email to