-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Build
-
None
If we add a conversion member to Status, we can use the idiom
switch (auto status = fun()) { case ErrorCodes::Error::NoSuchKey: break; default: return status; }
For this to be safe, we would need to change Error to an "enum class". Otherwise, the implicit promotion ErrorCodes::Error -> int would allow a Status to be passed to a function taking int. That change would, in turn, require changing mentions of "ErrorCodes::<name>" to "ErrorCodes::Error::<name>", as seen above.
Alternatively, the type Error could be eliminated, and the enumerators promoted to an enum class ErrorCodes. That would require changing the ErrorCodes static members to namespace-scoped functions.
Or, the enum type Error could be left with no enumerators, but instead define constexpr values in ErrorCodes. That would not require changes in most uses of ErrorCodes, and the idiom would look like
switch (auto status = fun()) { case ErrorCodes::NoSuchKey: break; default: return status; }