What's the point of using it when you can just use a plain static allocated string array?
Enums are useful when you want to represent a bunch of distinct values, like colors Red, Green & Blue, or genders Male and Female. There are plenty of times when you want to represent these as numbers rather than strings.
Although representing the strings with a map will work, notice that the map doesn't change during the lifetime of the program and neither do the strings. As a result, you'll be bringing in a lot of extra code that isn't really necessary.
On my system, your existing code compiles into an executable that looks like this:
$ size foo
text data bss dec hex filename
3877 2072 272 6221 184d foo
|
This says that the code takes 3877 bytes, initialized data takes 2072 bytes and uninitialized data takes 272 bytes for a total of 6221.
Using a map<Day,std::string>, the size more than doubles:
$ size foo
text data bss dec hex filename
12885 2796 304 15985 3e71 foo |
An alternative is a simple array of cstrings:
1 2 3 4 5 6 7 8 9
|
const char *dayMap[] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
|
With this the size goes up by 140 bytes instead of 9,700+:
$ size foo
text data bss dec hex filename
3937 2152 272 6361 18d9 foo
|
I'm not trying to slam std::map<>, I'm just pointing out that it comes with a cost in space so when the map doesn't change it might not be the right alternative.