I often use unordered_maps with fixed / persistent keys but mutable values. Example. If you have one enum Dimension{ X, Y }, you can save a data point for everyone, but never allow insertion or deletion for a map. Updates are fine.
Initialization Example:
typedef std::unordered_map<Dimension, std::size_t> Dimension_To_Size_Map;
Dimension_To_Size_Map dimension_To_Size_Map =
{ { Dimension.X, 0 }, { Dimension.Y, 0 } };
dimension_To_Size_Map[Dimension.X] = 12;
dimension_To_Size_Map[Dimension.Y] = 17;
dimension_To_Size_Map[(Dimension)7] = 22;
dimension_To_Size_Map.erase(Dimension.X);
Can I prevent insertion or erasure, but allow the update, on the STL unordered_map?
One idea: copy, rename and modify the existing implementation unordered_mapto remove insertand erase.
source
share