Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 01, 2008 associative array and function | ||||
---|---|---|---|---|
| ||||
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"); } |
August 01, 2008 Re: associative array and function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | Reply to Zarathustra, > only input data is modified > are you asking a question or pointing out an issue or just replying to that last thread? > 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"); > } |
August 01, 2008 Re: associative array and function | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS Wrote: are you asking a question or pointing out an issue or just replying to that last thread? Is it a issue? What do you think about it? |
August 01, 2008 Re: associative array and function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | 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.
|
Copyright © 1999-2021 by the D Language Foundation