Understanding decltype in C++ type deduction
This is an easy C++ language-knowledge question that tests your grasp of decltype and how it interacts with type deduction rules. It's the kind of foundational question that appears in technical screens at firms that rely heavily on modern C++, especially where template metaprogramming or generic code is central to the codebase.
Decltype behaves subtly in different contexts: the rules for what type it yields depend on whether its argument is a parenthesized expression, a variable, a function call, or an lvalue reference. Getting this right requires understanding the distinction between the declared type of an entity and the type that decltype actually reports, including whether references are preserved or collapsed.
- Decltype with variables, expressions, and function return types
- Lvalue and rvalue reference forwarding in type deduction
- How parentheses change decltype's behaviour