For an associative array, what is the best idiom that allows for checking if a key exists in the AA. If it does do something with the value, if not initialize the value and then do something with it.

In this code: http://dpaste.dzfl.pl/daab318f

How would this piece be improved? It looks like it would have to perform the hash and do a find 3 times:

    auto exists = (k in _dataMap);
    if(!exists) {
      _dataMap[k] = init;
      exists = (k in _dataMap);
    }
    ... use *exists

At a higher level and assuming the general goal of this basic struct is clear, any other suggestions welcome.

Also, an FYI to dpaste maintainer that the compiler service has been unavailable for a while.

Thanks
Dan

Reply via email to