"in" operator gives a pointer result from a test against an Associative Array?

Andy Valencia dont at spam.me
Fri May 10 01:00:09 UTC 2024


On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote:
> Yes. The reason for this is that it avoids having to 
> essentially do the same check twice. If `in` returned a bool 
> instead of a pointer, after checking for whether the element 
> exists (which requires searching for the element in the 
> associative array), you'd then have to actually *get* it from 
> the array, which would require searching again. Returning a 
> pointer to the element if it exists (or `null` if it doesn't) 
> cuts this down to 1 operation.

Looking at Programming in D section 28.5, I'm guessing that 
pointer versus null is treated as the appropriate boolean value 
when consumed by an "if" test.  So that example is getting a 
pointer to a string, or null, but the example looks exactly as 
the same as if it had directly gotten a bool.

Thank you!
Andy



More information about the Digitalmars-d-learn mailing list