Exception-Free Result Type

Medium C++ Robustness Asked at Tesla
Solve this problem

Firmware builds usually disable exceptions. Implement a Result type that carries either a value or an error code and forces the caller to check before reading.

Constraints

  • Template on the value type and a fixed error enum.
  • `value()` on an error state must trigger a hard fault hook, not undefined behaviour.
  • No exceptions, no RTTI.
  • Must support a void value type.
  • Move-constructible.
  • Zero heap allocation.
Starter codeC++
1#include <cstdint>2 3enum class Error { kNone, kTimeout, kCrc, kBusy };4 5template <typename T>6class Result {7    // TODO8};