Circular Iterator Adapter

Medium C++ Abstraction Asked at Western Digital
Solve this problem

Wrap a fixed array in an iterator that wraps around at the end, so a round-robin scheduler can walk it forever without an explicit modulo at every call site.

Constraints

  • Must satisfy the forward iterator requirements for reading.
  • ++ at the last element must return to the first.
  • Provide a way to detect a full lap so callers can terminate.
  • No allocation.
  • Must work with a C array and with std::array.
Starter codeC++
1#include <cstddef>2 3template <typename T>4class CircularIterator {5    // TODO6};