Recap on the modern C++ talks

Recap on the modern C++ talks

·

3 min read

we first talked about the template and how the type deduction plays a critical role in the usage of other declarations like auto. In the three cases where the template type deduction is used,

  1. paramtype is a reference or pointer. but not universal

  2. paramtype is a universal reference

  3. paramtype is neight pointer or reference-pass by value

after we now know the rules of the type deduction we forgot to talk about the list and function initialize. but, we handle this in the case of auto-type deduction. as it is one of the powerful advantages of the auto. and we mentioned the main difference between the two methods- the initialization using braces resulting in a new object type std::initializer_list<type> in both seniors but in the case of auto, the explicit std::initializer_list is not declared. plus the return type of lambda using auto implies the type deduction not the auto type deduction.


we moved to decltype to avoid the anxiety of knowing the return type of the function overhead and avoid the type deduction results from using auto as type definition to the function. as the dectype yields the type of the variable or expression without any modifications on the type- no type deduction rule is used. for all lvaule the result of the decltype is always type&. but be careful when using the decltype with auto as the return is laws a reference but if the reference is to a local var then it is a dilemma.

decltype(auto) f1(){int x{0} return x;}

the auto initializer is a better way of using the type declaration interface. as the vars declared using auto are immune to type mismatch. still subject to pitfalls.


the third article was too bullish on the new ways of declaring vars and the difference between the () and{} and how each one has better scope in a specific problem. as the braced prevents the narrowing conversion and it is immune to vexing parse-where the object declared using class may be compiled as a function definition. the drawbacks of the brase happen when using std::initializer_list occurs to exist as the braces always refer to this constructor even if there is another default constructor. just like vectors when using {} we declare a list with initial values but when using () we declare a container with a specific size and initial values for all the elements.


then we faced the NULL,0 or nullptr. and this was the first time to say in a loud voice use nullptr when you know you are dealing with the pointer. as the other two are technically declared as int type when passing to templates.

the last two articles were about the typdef and alias and the constexpr. we noticed the alias becomes more intuitive to use more than the typedef and the constexpr introduced the topic of blurring the difference between the run time and compile time.

next series about pointers and how it is critical in many cases.

WOW code

int array[]={1,2};
cout<<array[0]<<"="<<0[array]<<endl; 
// 1=1