Thread overview
using tuple as value type for associative array
Jun 21, 2018
Flaze07
Jun 21, 2018
Computermatronic
Jun 21, 2018
Flaze07
June 21, 2018
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
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
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