Advertisement

015 - The Most Effective Way of Learning C++ Types, auto, auto&, auto&&, decltype, decltype(auto)

015 - The Most Effective Way of Learning C++ Types, auto, auto&, auto&&, decltype, decltype(auto) Rule of Thumbs:
1. Use auto for iterators in the STL algorithms.
2. Use auto& to enumerate elements of STL containers in the ranged-for.
3. Use auto&& as the parameter types of lambdas.

4. Use auto as return type when we return an instance using copy-semantic
or internally move semantic.

For example, we can use auto as return type when we return
an instance of shared_ptr or unique_ptr

5. Use auto& as return type when we return a data member of a class from
a member function.

6. Use auto&& as return type when we return an rvalue reference from an operator function.

7. Use decltype(auto) as return type when Rule 4, 5, 6 are not suitable.


Template Metaprogramming 30 - auto, auto&, auto&&, decltype, decltype(auto)


Template Metaprogramming 31 - Type Decay and Perfect Forwarding


Useful resources


Prerequisites:

014 - Must-Know Must-Understand Type Function - std::remove_cvref_t


013 - Understanding and Extending C++ Standard Template Library - is_same_v


012 - How to Use Function Pointer, Function Alias with using and typedef


000 - Install Microsoft Visual Studio, GNU g++, clang++, Intel TBB


Download Source Code:



Episode 015


Episode 014


Episode 013


Episode 012

lvalue,lvalue reference,rvalue,rvalue reference,auto,auto&,auto&&,decltype,decltype(auto),

Post a Comment

0 Comments