Thread overview | |||||
---|---|---|---|---|---|
|
June 21, 2018 using tuple as value type for associative array | ||||
---|---|---|---|---|
| ||||
when I do Tuple!(uint, "first", uint, "second")[string] what; //I tried aliasing the tuple as well what["something"].first = 20; I get range error but when I do uint[string] what2; what2 = 20; I get none of those range error, so...how do I use tuple as value type for associative array ? |
June 21, 2018 Re: using tuple as value type for associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On Thursday, 21 June 2018 at 02:44:12 UTC, Flaze07 wrote:
> when I do
> Tuple!(uint, "first", uint, "second")[string] what; //I tried aliasing the tuple as well
> what["something"].first = 20;
> I get range error
> but when I do
> uint[string] what2;
> what2 = 20;
> I get none of those range error, so...how do I use tuple as value type for associative array ?
what["something"].first = 20 will attempt to get an element of what, then assign a member, while what2["something"] = 20 will add an element to what2 with the value of 20. Since what["something"] is not present, it will throw a range error.
Try what["something"] = tuple(20, 0); instead.
|
June 21, 2018 Re: using tuple as value type for associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Computermatronic | On Thursday, 21 June 2018 at 03:04:46 UTC, Computermatronic wrote:
> On Thursday, 21 June 2018 at 02:44:12 UTC, Flaze07 wrote:
>> when I do
>> Tuple!(uint, "first", uint, "second")[string] what; //I tried aliasing the tuple as well
>> what["something"].first = 20;
>> I get range error
>> but when I do
>> uint[string] what2;
>> what2 = 20;
>> I get none of those range error, so...how do I use tuple as value type for associative array ?
>
> what["something"].first = 20 will attempt to get an element of what, then assign a member, while what2["something"] = 20 will add an element to what2 with the value of 20. Since what["something"] is not present, it will throw a range error.
>
> Try what["something"] = tuple(20, 0); instead.
huh, interesting, thanks
|
Copyright © 1999-2021 by the D Language Foundation