What this C++ template specialization question tests
This is a medium-difficulty C++ question that probes your understanding of template specialization rules — specifically, how the compiler resolves which specialization to instantiate when multiple candidates exist. It's the kind of question trading firms ask to verify you can reason precisely about template dispatch, a critical skill when writing performance-sensitive generic code.
To answer correctly, you need to understand the difference between primary templates, partial specializations, and explicit (full) specializations, and how the compiler ranks them by specificity. The tricky part is that partial specializations can overlap, and the language has strict rules about which one wins. Getting this wrong in production code leads to subtle bugs or unexpected performance cliffs.
- Primary vs. partial vs. explicit specialization
- Specialization ordering and resolution rules
- Parameter deduction and template argument deduction
- Ambiguity and compiler errors in specialization hierarchies