I have a problem where I need to map an integer at compile time to another integer. Basically, I need the compile-time equivalent of std::map
. If
You can use template specialization
template
struct Map;
template
struct Map { static const int value = -1; }; // not exists node
template <> struct Map< 'A' > { static const int value = 1; }; // 'A' -> 1
template <> struct Map< 'B' > { static const int value = 2; }; // 'B' -> 2
// ....
int lookup = Map<'B'>::value; // = 2
You can avail yourself of some macros to simplify the definition of content.