Boost logo

Boost Users :

Subject: [Boost-users] Static map like array or range?
From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2013-09-15 15:55:14

I find myself often building lookup tables for conversion or mapping of one piece of data to another. Common conversions include

* converting from one string to a different string (e.g. text translation),
* converting from an enum to a descriptive string
* converting from a string to an enum
* converting from a string to a function or functor

The key aspect of these lookup tables is that they are static. If the table is reasonably large, say 7-10 items, I ensure that the table is presorted and use lower_bounds() to search the table.

Some uses have started using map_list_of() to initialize the map. My inner optimizer finds this disturbing as inherently static information is being allocated dynamically in order to due to the lookup.

I believe it would be more intuitive if there was a map like interface to the lookup table. The implementation would use the static nature of the data to its advantage. In particular the implementation would not require the data to be copied, re-allocated, etc.

I've been searching the boost libraries, but have not been able to find something like this.

Thank you for your suggestions.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at