Often times you see things like
std::map<std::string, somethingelse> m_named_objects;
or
std::string state;
//...
if(state == "EXIT")
exit();
else if(state == "california")
hot();
where people use strings purely to make something more readable. The same thing could easily be achieved with something like integer-IDs.
Can modern compilers (msvc, g++, etc.) usually employ special optimizations for these types of cases? Or should this be avoided because of bad performance or for other reasons?
As far as I know, compilers don’t make those kinds of optimizations. It’s definitely not a “standard” optimization.
At least for your second case, it seems to me that enumerations are more readable and can be faster (since integer comparisons are rather cheap relative to string comparison).