I want to be modify an associative array by reference from another function. However null associative arrays are pass by value. How do I generically create an empty associative array?
---
import std.stdio;

void addElement(int[int] data){
        data[0] = 0;
}

void nonempty() {
        int[int] items = [1 : 1];
        writeln(items); // [1 : 1]
        addElement(items);
        writeln(items); // [0 : 0, 1 : 1]
}

void empty(){
        int[int] items = null;
        writeln(items); // []
        addElement(items);
        writeln(items); // []
}

void main(){
        nonempty();
        empty();
}
---

Reply via email to