final

  1. final is a way to forbid you overriding a virtual function again
    1. It should not be used with override as it implies override
  2. final allows compilers to do optimization1

Base virtual destructor

  1. Base virtual destructor implies children virtual destructor, so we can use rule of 0 here.

Small Integer Operations 2

  1. When doing arithmetic operations on small unsigned integers (those with rank less than int), they will be promoted to int 3
    1. the deducted return type with auto will become int
    2. any further operations on this value (e.g. right shift) are operating on int, which can yield unexpected impact
  2. To solve this problem, when doing arithmetic operations on small unsigned integer, we need to use static_cast to change their type back to the original unsigned type

Weird vector bool 4

  1. C++ standard “recommends” a space-optimized specialization of std::vector<bool>
    1. This optimization works by actually placing bool inside a bit
  2. However, if we need to access the member inside the list, the operator[] returns a proxy object for us
    1. that allows us to view/change the value
  3. But the proxy project cannot be bound to lvalue reference auto & while other instantiation of vector all allow you to auto &ref = v[idx]
    1. To store the proxy object, you need to use auto sth = v[idx]
    2. If you want to use bit field by yourself, you cannot bind the member by reference either

  1. Compilers are allowed to call function directly instead of following vtable. See this answer for more details. ↩︎

  2. See Jason Turner’s video C++ Weekly - Ep 310 - Your Small Integer Operations Are Broken! for more details. ↩︎

  3. cppreference provides a detailed explanation about arithmetic conversions and integer promotions ↩︎

  4. See Jason Turner’s video C++ Weekly - Ep 325 - Why vector of bool is Weird for more details. ↩︎