Implement std::optional
What this preview is
Implement std::optional is a hard quant coding problem on language knowledge in Cpp, asked at Quant.
- Difficulty
- Hard
- Topic
- Language Knowledge
- Discipline
- Quant development
- Language
- Cpp
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
sizeoffor 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
Unlock full access to getcracked
Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.