3 ms·
In the version we ended up writing, 'operator []' is equivalent to a call to 'Get', which also returns a reference to the mapped value. In the event that key i
by cobrausn 14y ago
In the version we ended up writing, 'operator []' is equivalent to a call to 'Get', which also returns a reference to the mapped value. In the event that key is not mapped, it asserts. If you handle the assert or have disabled runtime asserts, it returns a reference to a static value instance, so you can handle this kind of error yourself or even use the static value as a 'default' (though we never use it that way).
Though not consistent with how STL works, it is consistent with how our containers work and how we use maps. YMMV.
Also, since we wrote it, we're free to change the behavior if a better way manifests itself. So, if you have any suggestions, let fly.