Understanding C++ decltype type deduction in practice
This is a medium-difficulty C++ language-knowledge question that tests your grasp of decltype type deduction rules. It requires you to trace through a code snippet and predict its output—or identify when it fails to compile.
Decltype has subtle behaviour that differs from auto and template type deduction. The core challenge is understanding when decltype preserves references, when it strips them, and how expression parenthesization and value categories (lvalue vs. rvalue) influence the deduced type. These distinctions matter in real codebases, especially when writing generic or metaprogramming code.
- Decltype on variables vs. expressions
- Parenthesized vs. non-parenthesized decltype arguments
- Interaction with references and const-qualification
- Compilation failure vs. runtime behaviour