Allocating an empty non null associative arary
Superstar64
Hexagonalstar64 at gmail.com
Tue Mar 31 02:51:11 UTC 2020
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();
}
---
More information about the Digitalmars-d-learn
mailing list