1 | template<typename T> |
Conclusion: when deducing types for universal reference parameters, lvalue arguments get special treatment
- T&& lvalue => (const) T& lvalue
- T&& rvalue => T&& rvalue
1 | void fun(); // type is void() |
Conclusion: during template type deduction, arguments that are function names decay to pointers, unless they are used to initialize references
1 | auto x = 27; |
Conclusion: same as template type deduction
1 | Widget w; |
1 | int x = 0; |
x is the name of a variable, so decltype(x) is int. Being a name, x is an lvalue, and C++ defines the expression (x) to be an lvalue, too. decltype((x)) is therefore int&.
Conclusion:
- decltype almost always yields the type of a variable or expression without any modifications.
- For lvalue expressions of type T other than names, decltype always reports a type of T&
1 | double f(); |
Conclusion: use explicitly typed initializer idiom for auto to deduce the type you want it to have