CRTP Driver Interface

Hard C++ Abstraction Asked at Intel
Solve this problem

Use the curiously recurring template pattern to give several peripheral drivers a common interface with no vtable and no indirect call.

Constraints

  • Base template `Driver<Derived>` provides init() and transfer().
  • Derived supplies do_init() and do_transfer().
  • No virtual functions anywhere.
  • Calling through the base must inline to the derived implementation.
  • A derived class missing do_init() must fail to compile.
Starter codeC++
1#include <cstdint>2 3template <typename Derived>4class Driver {5    // TODO6};