Notes for C++

  1. push_back() vs emplace_back()
    • copy vs move
    • vec.insert({a, b}) vs vec.emplace(a, b)
  2. const vs constexpr
    • const : could be compile-time or runtime constants
    • constexpr : enforces compile-time constants
    • Any variable that should not be modifiable after initialization and whose initializer is known at compile-time should be declared as constexpr.
    • Any variable that should not be modifiable after initialization and whose initializer is not known at compile-time should be declared as const.
    • https://www.learncpp.com/cpp-tutorial/compile-time-constants-constant-expressions-and-constexpr/
    • Don’t use const when passing by value.
    • Don’t use const when returning by value.