Enumerations
Enum.7
Specify the underlying type of an enumeration only when necessary
Reason
The default is the easiest to read and write. int is the default integer type. int is compatible with C enums.
Example
enum class Direction : char { n, s, e, w,
ne, nw, se, sw }; // underlying type saves space
enum class Web_color : int32_t { red = 0xFF0000,
green = 0x00FF00,
blue = 0x0000FF }; // underlying type is redundant
Note
Specifying the underlying type is necessary to forward-declare an enum or enum class:
enum Flags : char;
void f(Flags);
// ....
enum Flags : char { /* ... */ };
or to ensure that values of that type have a specified bit-precision:
enum Bitboard : uint64_t { /* ... */ };
Enforcement
????