cpp
[EMCpp]Item-5 Prefer Auto to Explicit Type Declarations
· β˜• 4 min read

Despite some pitfalls described in EMCpp item 2 and 6, auto variables are preferred for they must be initialized, are generally immune to type mismatches that can lead to portability or efficiency problems, can ease the process of refactoring, and typically require less typing than variables with explicitly specified types.


[EMCpp]Item-4 Know How to View Deduced Types
· β˜• 3 min read

Deduced types can often be seen using IDE editors, compiler error messages, and the Boost TypeIndex library, but the results of some tools may be neither helpful nor accurate.


[EMCpp]Item-3 Understand Decltype
· β˜• 4 min read

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&.


[EMCpp]Item-2 Understand Auto Type Deduction
· β˜• 4 min read

auto type deduction is usually the same as template type deduction, with an exception in the case of braced initializer. Also, in C++14, as a function return type or a lambda parameter, auto implies template type deduction instead of auto type deduction.


[EMCpp]Item-1 Understand Template Type Deduction
· β˜• 6 min read

There are three sets of rules for type deduction in modern C++: one for function templates, one for auto, and one for decltype. Without a solid understanding of how deduction operates, effective programming in modern C++ is all but impossible.