By providing something like: auto ptrToValue = hash.insertDefaultOrFind(key, init) *ptrToValue += additional; client code can perform an <insert if not present/lookup> combined so that on the case of a nonexistent key, 1 toHash/lookup can be done instead of 3. The best recap of what is needed is in this thread: http://forum.dlang.org/post/mailman.1081.1360269373.22503.digitalmars-d-learn@puremagic.com
I know exactly the kind of thing you are talking about. What you want is a setDefault function with an overload. These functions should have these signatures. ref V1 setDefault(K, V1, V2)(ref V1[K] map, K key, lazy V2 value) if (is(V2 : V1)); ref V setDefault(K, V)(ref V[K] map, K key); Where the second overload is equivalent to setDefault(map, key, V1.init) above. This is basically 'setdefault' from Python, only better because the value is lazy. I have written a higher level implementation of this myself before, but I believe a druntime implementation could do better by computing a hash for K once, like you say.
Since https://github.com/dlang/druntime/commit/0c92d13c7f8540bd91c3cce251d97ff39b84a486 (present in 2.082) there is now a require() function that does exactly that.