Enum Class Bitmask Operators

Easy C++ Abstraction Asked at Samsung
Solve this problem

A scoped enum gives you type safety but loses the bitwise operators. Add them back for a peripheral flags enum without giving up the type checking.

Constraints

  • Enum class `Flags : uint8_t` with Rx, Tx, Error, Overrun.
  • Provide operator| , operator& , operator~ and a has() helper.
  • Mixing Flags with a raw int must not compile.
  • Operators must be constexpr.
  • No macros.
Starter codeC++
1#include <cstdint>2 3enum class Flags : uint8_t {4    Rx = 1, Tx = 2, Error = 4, Overrun = 85};6 7// TODO: bitwise operators