Modern C++

Modules (C++20)

"Modules are orthogonal to namespaces."

lvalues and rvalues

An lvalue refers to an object that persists beyond a single expression. You can think of an lvalue as an object that has a name. All variables, including nonmodifiable (const) variables, are lvalues. An rvalue is a temporary value that does not persist beyond the expression that uses it.

A function call can be an lvalue if and only if the return value is a reference.

Casts

Arrays can be implicitly converted to pointers without casting: there is no implicit conversion from pointers to arrays. int* can be implicity converted to int const*: there is no implicit conversion from int const* to int*.

You can static cast a derived class pointer to a base class pointer but not the other way around.

Rule of three/five

If you declare any of copy, copy assignment or destructor then you should declare them all. Similarly, for C++11 onwards: rule of 5.

See wiki/Rule of three.

See rule of three/five/zero.

class base_of_five_defaults
{
  public:
    base_of_five_defaults(const base_of_five_defaults&) = default;
    base_of_five_defaults(base_of_five_defaults&&) = default;
    base_of_five_defaults& operator=(const base_of_five_defaults&) = default;
    base_of_five_defaults& operator=(base_of_five_defaults&&) = default;
    virtual ~base_of_five_defaults() = default;
};

The rule of the big four and a half

https://blog.feabhas.com/2015/01/the-rule-of-zero/

Classes and structures

The difference between a class and a struct is only the default accesses specifier: public: for struct and private: for class.

noexcept

References