I want something in c++ that come as close as possible to that usage.
enum foo
{
bar_0 = "hello",
bar_1 = "world"
};
//..
cout << to_string(bar_0) << " " << to_string(bar_1);
with output "hello world".
I'm aware of solution that looks like this
ENUM foo
{
bar_0 ,
bar_1
};
//..
cout << to_string(bar_0) << " " << to_string(bar_1);
//>bar_0 bar_1
and solutions like this
eunm foo
{
bar_0 ,
bar_1
};
std::string foo_to_string[] = { "hello", "world"}
//+ some static assert of the sizes
Is there something sweeter outside? I want something were the enum-value and the string is at the same line
P.S.: I'm accepting solutions containing some dark-side-cpp-macro-magic
EDIT
Why is this not a duplicate?
My question is different to the duplicate marked on, because i want custom strings and not the name of the enum value. One can argue, that i can change the name of the enum-value this does often not work. For example error-msg.
enum Error_msg
{
you_are_using_internet_behind_a_proxy,
};
No one want to use this kind of error-msg and enum-value name.