13.5 — Introduction to overloading the I/O operators

In the prior lesson (), we showed this example, where we used a function to convert an enumeration into an equivalent string: #include <iostream> #include <string_view> enum Color { black, red, blue, }; constexpr std::string_view getColorName(Color color) { switch (color) { case black: return “black”; case red: return “red”; case …

12.15 — std::optional

In lesson , we discussed cases where a function encounters an error that it cannot reasonably handle itself. For example, consider a function that calculates and returns a value: int doIntDivision(int x, int y) { return x / y; } If the caller passes in a value that is semantically …

B.5 — Introduction to C++23

What is C++23? In February of 2023, the ISO (International Organization for Standardization) approved a new version of C++, called C++23. New improvements in C++23 For your interest, here’s a list of the major changes that C++23 adds. Note that this list is not comprehensive, but rather intended to highlight …

16.5 — Returning std::vector, and an introduction to move semantics

When we need to pass a std::vector to a function, we pass it by (const) reference so that we do not make an expensive copy of the array data. Therefore, you will probably be surprised to find that it is okay to return a std::vector by value. Say whaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat? Copy …

5.5 — Constexpr variables

In the previous lesson , we defined what a constant expression is, as well as a compile-time constant. This lesson continues that discussion. When you declare a const variable using the const keyword, the compiler will implicitly keep track of whether it’s a runtime or compile-time constant. In most cases, …