associative arrays: how to insert key and return pointer in 1 step to avoid searching twice

Daniel Kozak via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 7 00:26:31 PDT 2016


Dne 7.9.2016 v 09:21 R via Digitalmars-d napsal(a):

> On Tuesday, 6 September 2016 at 04:32:52 UTC, Daniel Kozak wrote:
>> Dne 6.9.2016 v 06:14 mogu via Digitalmars-d napsal(a):
>>
>>> On Tuesday, 6 September 2016 at 01:17:00 UTC, Timothee Cour wrote:
>>>> is there a way to do this efficiently with associative arrays:
>>>>
>>>> aa[key]=value;
>>>> auto ptr=key in aa;
>>>>
>>>> without suffering the cost of the 2nd search (compiler should know 
>>>> ptr during aa[key]=value but it's not exposed it seems)
>>>
>>> auto pa = &(aa[key] = value);
>>
>> Yep, but this is a implementation detail, so be careful
>
> :D then make a pull-request to the D test suite...
>
> Bham! Its in the spec if its merged.
And idealy to doc too ;)



More information about the Digitalmars-d mailing list