I love STL containers in C++. They're so much better in general
to work with than their C counterparts. The bit that's missing
though is an instantiation-time optimized version of map.
Take, for instance, reading a set of commands at startup from a
set of dynamically loaded plugins. It's not going to change, in
this hypothetical case, because we neither load nor unload
plugins after startup. But it's dynamic in the sense that we do
not know it at compile time - so doing something like gperf to
generate a perfect hash is out of the question.
But why should we pay the lookup cost on a dynamic container for
every lookup if I can determine, based on program flow, that the
contents of the container are not going to change once it's
instantiated.
Something like:
const perfect_map(some_dynamic_map_I_built);
Where the constructor would do a perfect hash generation once,
and the map itself would be const (not …
[Read more]