frozen

a header-only, constexpr alternative to gperf for C++14 users

Automatically checked · GitHub checked 2026-11-16

frozen

Overview

.. image:: https://travis-ci.org/serge-sans-paille/frozen.svg?branch=master :target: https://travis-ci.org/serge-sans-paille/frozen Header-only library that provides 0 cost initialization for immutable containers, fixed-size containers, and various algorithms. - immutable (a.k.a. frozen), constexpr-compatible versions of std::set, std::unordered_set, std::map and std::unordered_map. - fixed-capacity, constinit-compatible versions of std::map and std::unordered_map with immutable, compile-time selected keys mapped to mutable values. - 0-cost initialization version of std::search for frozen needles using Boyer-Moore or Knuth-Morris-Pratt algorithms. The unordered containers are guaranteed perfect (a.k.a. no hash collision) and the extra storage is linear with respect to the number of keys. Once initialized, the container keys cannot be updated, and in exchange, lookups are faster. And initialization is free when constexpr or constinit is used :-). 1. The master version can be used as the default stable version. 2. It is in maintenance mode. I still accept commits that make the code cleaner | faster | more modern, but expect some latency in the review process. A C++ compiler that supports C++14. Clang version 5 is a good pick, GCC version 6 lags behind in terms of constexpr compilation time (At least on my setup), but compiles correctly. Visual Studio 2017 also works correctly! Note that GCC 5 isn't supported. (Here's an old compat branch where a small amount of stuff was ported.) .. old compat branch: https://github.com/cbeck88/frozen/tree/gcc5-support The associative containers have different functionality with and without constexpr. With constexpr, frozen maps have immutable keys and values. Without constexpr, the values can be updated in runtime (the keys, however, remain immutable): For compatibility with STL's API, Frozen may eventually throw exceptions, as in frozen::map::at. If you build your code without exception support, or define the FROZEN_NO_EXCEPTIONS macro variable, they will be turned into an std::abort. Just like the regular C++14 container, you can specialize the hash function, the key equality comparator for unordered containers, and the comparison functions for the ordered version. It's also possible to specialize the frozen::elsa structure used for hashing. Note that unlike std::hash, the hasher also takes a seed in addition to the value being hashed. [...] note: constexpr evaluation hit maximum step limit; possible infinite loop?