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.6 — Constexpr variables

In the previous lesson , we defined what a constant expression is, discussed why constant expressions are desirable, and concluded with when constant expressions actually evaluate at compile-time. In this lesson, we’ll take a closer look at how we create variables that can be used in constant expressions in modern …

11.4 — Deleting functions

In some cases, it is possible to write functions that don’t behave as desired when called with values of certain types. Consider the following example: #include <iostream> void printInt(int x) { std::cout << x << ‘\n’; } int main() { printInt(5); // okay: prints 5 printInt(‘a’); // prints 97 — …