What about a simple streaming overload? You still have to maintain the mapping if you don't want to do some macro magic, but I find it cleaner than your original solution.
#include // for std::uint_fast8_t
#include
#include
#include
enum class MyEnum : std::uint_fast8_t {
AAA,
BBB,
CCC,
};
std::ostream& operator<<(std::ostream& str, MyEnum type)
{
switch(type)
{
case MyEnum::AAA: str << "AAA"; break;
case MyEnum::BBB: str << "BBB"; break;
case MyEnum::CCC: str << "CCC"; break;
default: break;
}
return str;
}
int main()
{
std::cout << MyEnum::AAA <<'\n';
}