AA with dynamic array value
Craig Dillabaugh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 5 18:58:31 PDT 2016
How can I create (and update) and associative array where the key
is a string, and the value is a dynamic array of integers?
For example:
void insertValue( int[][string]aa, string key, int value )
{
int[]* keyvalue;
keyvalue = ( key in aa );
if ( keyvalue !is null )
{
*(keyvalue) ~ value; // This line fails.
}
else {
int[] tmp;
tmp ~= value;
aa[key] = tmp;
}
}
int main( string[] args) {
int[][string] myAA;
insertValue( myAA, "hello", 1 );
insertValue( myAA, "goodbye", 2 );
insertValue( myAA, "hello", 3 );
return 0;
}
Fails with:
...(16): Error: ~ has no effect in expression (*keyvalue ~ value)
Thanks for any help.
More information about the Digitalmars-d-learn
mailing list