Search code examples
c++dictionaryassociative-arraystdmap

C++ fixed-capacity associate container


I am looking for a container like std::unordered_map that does not use any dynamic allocation. I believe this would be the case for any associate container with a fixed number of keys, or even keys that have to be chosen at compile time.

I am not looking for a constexpr or compile time hash map because I would like to be able to update the values in the map.

Example use case:

FixedCapacityMap<std::string_view, int> fruits {
  {"n_apples", 0},
  {"n_pairs", 0}
}

fruits["n_apples"] += 1;
fruits["n_pairs"] += 1;

Does anyone know if such a library exists, and if not how something like this could be implemented?


Solution

  • I was able to find a library with this functionality:

    https://github.com/serge-sans-paille/frozen

    It allows for constexpr and constinit ordered and unordered maps with (newly added by me) the ability to update values in runtime.