Re: Allocating an empty non null associative arary

2020-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/20 9:41 AM, Superstar64 wrote: On Tuesday, 31 March 2020 at 06:51:16 UTC, WebFreak001 wrote: This doesn't only happen with null, you will notice that that function will eventually not add anything if you only add values. This is because by adding values you might reallocate the map at

Re: Allocating an empty non null associative arary

2020-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/20 2:51 AM, WebFreak001 wrote: On Tuesday, 31 March 2020 at 02:51:11 UTC, Superstar64 wrote: 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? ---

Re: Allocating an empty non null associative arary

2020-03-31 Thread Superstar64 via Digitalmars-d-learn
On Tuesday, 31 March 2020 at 06:51:16 UTC, WebFreak001 wrote: This doesn't only happen with null, you will notice that that function will eventually not add anything if you only add values. This is because by adding values you might reallocate the map at some other place in memory and because

Re: Allocating an empty non null associative arary

2020-03-31 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 31 March 2020 at 02:51:11 UTC, Superstar64 wrote: 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]

Re: Allocating an empty non null associative arary

2020-03-31 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 31 March 2020 at 02:51:11 UTC, Superstar64 wrote: How do I generically create an empty associative array? If you can't pass it by ref, then adding and then removing an element is the only way I know. /// Ensure that arr is non-null if empty. V[K] nonNull(K, V)(V[K] aa) {

Re: Allocating an empty non null associative arary

2020-03-30 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 31 March 2020 at 02:51:11 UTC, Superstar64 wrote: 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]

Allocating an empty non null associative arary

2020-03-30 Thread Superstar64 via Digitalmars-d-learn
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() {