associative array and function

BCS ao at pathlink.com
Fri Aug 1 13:02:20 PDT 2008


Reply to Zarathustra,

> only input data is modified
> 
> module main;
> import std.stdio;
> import std.process;
> void Function(in uint[int]o_a){
> foreach(l_a; o_a.keys)o_a.remove(l_a);
> }
> void
> main(char [][] args){
> uint[int]l_a;
> l_a[1] = 0;
> l_a[2] = 3;
> writefln(l_a.length);  // 2
> Function(l_a);
> writefln(l_a.length);  // 0
> system("pause");
> }

That act's as I would expect. (AA's are reference objects) If you want to 
not effect the AA on the outside then set it to null (better check that) 
on the inside function. If you want to remove only some things and only do 
/that/ on the inside, your sunk.




More information about the Digitalmars-d-learn mailing list