Template metaprogramming at compile time: variadic type manipulation
This is a hard C++ coding problem that tests your fluency with template metaprogramming—specifically, how to manipulate variadic template parameters and create new types at compile time. Quant firms use questions like this to identify candidates who can write code that does real computational work before the program runs, a skill valuable in high-performance trading systems where every runtime cycle counts.
The core challenge is to design a template that accepts a value and an existing Numbers class (itself a variadic template), then produces a new type with that value appended. You'll need to understand how to unpack and repack variadic parameter packs, use template specialization to match patterns, and leverage the ::type member pattern (or C++20 using type = syntax) to expose the result. Edge cases like empty Numbers classes are fair game.
- Variadic templates and parameter pack expansion
- Template specialization and partial specialization
- Type aliases and the
::type idiom
- Compile-time type checking with
static_assert and std::is_same_v