Associative arrays return from opIndexAssign the inserted or existing element by value. Why don't they return it by reference, which would be much more useful? Maybe not very common, but here's an example of the kind of situation where I actually would have needed it:

int[string] values;

foreach (string key; keys)
{
    int* ptr = key in values;

    if (ptr == null)
    {
        // Currently cannot write this:
        // ptr = &(values[key] = initValueFor(key));

        // The workaround is inefficient:
        values[key] = initValueFor(key);
        ptr = key in values;
    }
    edit(*ptr);
}

Reply via email to