Placement New Object Pool

Hard C++ Memory Asked at Micron
Solve this problem

Build a typed object pool that constructs objects in pre-reserved storage with placement new, so allocation is deterministic and the heap is never touched.

Constraints

  • Storage must be correctly aligned for T using alignas.
  • `create(args...)` forwards constructor arguments.
  • `destroy(ptr)` must call the destructor explicitly.
  • Returns nullptr when exhausted.
  • No new/delete, no std::vector.
  • Must work for a type with no default constructor.
Starter codeC++
1#include <cstddef>2#include <new>3#include <utility>4 5template <typename T, size_t N>6class ObjectPool {7    // TODO8};