You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now output stream operator includes a set of if statements, which might be inefficient if there are many different enum values. It could be much better if it's replaced by switch statement.
Also it would be very useful to have a separate free function to get const char * of enum. Output stream operator could use the function.
In this case switch statement will generate: error C2196: case value 'enums::EnumByte::ENUM_VALUE_0' already used error C2196: case value 'enums::EnumByte::ENUM_VALUE_3' already used
In this case switch statement will generate: error C2196: case value 'enums::EnumByte::ENUM_VALUE_0' already used error C2196: case value 'enums::EnumByte::ENUM_VALUE_3' already used
So it means only an alias. And it could be handled, couldn't it? Ok, I just wanted to point it out.
Enum value string is rarely used outside struct's dumps in logs. So << operator is more suitable. In case you need string equivalent try:
Yes, such cases are rare, but they are. This way(using std::stringstream) has a huge overhead(comparing to getting const char * from switch statement).
Yes, such cases are rare, but they are. This way(using std::stringstream) has a huge overhead(comparing to getting const char * from switch statement).
Since this is a C++17 library, an std::string_view would be a more appropriate return type.
Activity
chronoxor commentedon Dec 15, 2020
FBE protocol spec allows to declare enums with duplicate values:
In this case switch statement will generate:
error C2196: case value 'enums::EnumByte::ENUM_VALUE_0' already usederror C2196: case value 'enums::EnumByte::ENUM_VALUE_3' already usedchronoxor commentedon Dec 15, 2020
Enum value string is rarely used outside struct's dumps in logs. So << operator is more suitable. In case you need string equivalent try:
herolover commentedon Dec 15, 2020
So it means only an alias. And it could be handled, couldn't it? Ok, I just wanted to point it out.
Yes, such cases are rare, but they are. This way(using
std::stringstream) has a huge overhead(comparing to gettingconst char *fromswitchstatement).bitbugprime commentedon Feb 8, 2021
Since this is a C++17 library, an std::string_view would be a more appropriate return type.