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

Orvid King blah38621 at gmail.com
Fri Sep 13 07:17:00 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?

Well, I usually do it as:

int[string] someCache;

int getValue(string key)
{
     if (auto val = key in someCache)
         return *val;
     return someCache[key] = -3;
}


More information about the Digitalmars-d-learn mailing list