Logo

Coding preview

Implement std::optional

What this preview is

About this preview

Implement std::optional is a hard quant coding problem on language knowledge in Cpp, asked at Quant.

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.

Implementing a stack-or-heap optional type in C++11

This hard coding problem tests whether you can design and implement a type-safe nullable wrapper that makes intelligent runtime decisions about memory layout. It's the kind of systems-level problem quant trading firms pose to assess both language mastery and performance awareness.

The core challenge is conditionally choosing between stack and heap storage based on the size of the contained type, while maintaining a fixed external footprint for large types. You'll need to reason about alignment, object lifetime, placement construction, and destructors. The constraint that copy and move operations are deleted forces you to think carefully about how the optional itself is used and passed around.

  • Type traits and sizeof for compile-time storage strategy selection
  • Placement new and manual destruction for in-place object construction
  • Union or conditional storage to overlay stack and heap representations
  • Explicit operator bool and value accessors
  • Memory layout and alignment under strict size constraints