A Tour of C++ Part I

A Tour of C++ Part I


Language (Chapter 1-7)

Chapter 1

  1. The std:: is used to specify the standard-library namespace.
    I wonder does there exist other namespaces?
    Why we need a namespace in C++?
    I don’t see a similar thing in C or other languages.
  2. I’m interested in the usage of ‘auto’ keyword to define a type implicitly.
    By using auto, the redundancy of the code could be significantly reduced and it provides convenience for the programmer since sometimes the exact type of an object could be unknown.
    I think in the book, it would be better if the author could show some cases where ‘auto’ is not appropriate to be used (if there is any).
  3. The notion of immutability : ‘constexpr’ kind of surprised me.
    Only know about ‘const’ before, but the ‘constexpr’ clearly is efficient and helpful.
    Compile-time evaluation allows placement of data in read-only memory and improvement for performance.
    It would be great if there is an example of comparing const and constexpr functions.
  4. It’s interesting to understand how language primitives map to hardware.
    An array is C++’s basic abstraction of “a contiguous sequence of objects in memory”.

Chapter 2

  1. Good to know the ‘union’, which can save space in some specific situations.
    A variant can encapsulate the ‘union’ , it is safer and simpler to be used.

Chapter 3

  1. Separate compilation can minimize compilation time and separate logically distinct part of the program.
    The graph which represents the program fragments is very helpful to help understand. At first, I don’t understand why user.cpp can use Vector without including the Vector.cpp
  2. Impressed by the module features in C++20.
    Multiple imported modules will not interfere with each other, which is really cool.
    The maintainability and performance efficiency could be improved a lot.
  3. Now I understand the usage of namespace after reading the Namespace section in Chapter3.
    Namespace is offered as a mechanism for expressing that some declarations belong together and avoid conflicts.
  4. Structured Binding is very impressive. Combining using auto keyword, we can give local names to members of a class object without knowing the exact types.

Chapter 4

  1. Container is an interesting concept in C++.
    It seems not quite clearly explained when the object execute its destructor.
    The destructor is very intuitive to make sure the resource realize and avoid memory leak.
  2. Curious about the difference between garbage collector in C++ and Java.
  3. The concept of ‘unique_ptr’ is impressive. By avoiding using raw pointers, we can avoid the potential memory leak.

Chapter 5

  1. The definitions of moving containers and rvalue reference are confusing to me.

Chapter 6

  1. I think the constrained template in C++ is very impressive. But since we have to check whether T has all properties that a class requires every time, will the performance be impacted? Is that because it’s a compile-time mechanism?
  2. It’s a little surprising that “hello” would be indicated as a const char* type. Should be cautious when using the type deduction.

Chapter 7

  1. In the code example under Concepts section7.2, shouldn’t the template should be defined as template since it’s C++20?
  2. The explanation of the process of generalizing from a concrete code is very intuitive.
  3. Interested to know that the typename ‘…’ indicates a sequence of types and the fold expression.