What is the preferred method for testing the existence of a key in an associative array?

Adam D. Ruppe destructionator at gmail.com
Fri Sep 13 07:06:49 PDT 2013


On Friday, 13 September 2013 at 14:03:48 UTC, Gary Willoughby 
wrote:
> What is the preferred method for testing the existence of a key 
> in an associative array?

I use the in operator:

if(key in aa) {
   there
}

if(key !in aa) { not there}


You can also fetch the pointer right there too:

if(auto pvalue = key in aa) {
   auto value = *pvalue;
   // go ahead and use it
}


More information about the Digitalmars-d-learn mailing list