I would like to be able to write:
cout << enumalpha << Monday;
and get printed on console:
Monday
P.S. Monday is an enum type.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Okay, let’s go all preprocessor then 🙂
Intended way of use:
Dark magic, involving the helpful Boost.Preprocessor library.
There are better ways, personally I use this little macro to store that all in a nicely sorted vector of pairs, static for the type, it also allows me to iterate through the values of the enum if the mood (or need) strikes 🙂
It’s quite unfortunate though there is no support in the language for that. I would prefer if there was, enum are quite handy for codesets…