15.4a — std::move_if_noexcept

(h/t to reader Koe for providing the first draft of this lesson!)

In lesson 14.9 — Exception specifications and noexcept, we covered the noexcept exception specifier and operator, which this lesson builds on.

We also covered the strong exception guarantee, which guarantees that if a function is interrupted by an exception, no memory will be . . . → Read More: 15.4a — std::move_if_noexcept

14.9 — Exception specifications and noexcept

(h/t to reader Koe for providing the first draft of this lesson!)

In C++, all functions are classified as either non-throwing (do not throw exceptions) or potentially throwing (may throw an exception).

Consider the following function declaration:

Looking at a typical function declaration, it is not possible to determine whether a function might throw . . . → Read More: 14.9 — Exception specifications and noexcept

S.4.4c — Using a language reference

Depending on where you’re at in your journey with learning programming languages (and specifically, C++), might be the only resource you’re using to learn C++ or to look something up. is designed to explain concepts in a beginner-friendly fashion, but it simply can’t cover every aspect of the language. As you begin to . . . → Read More: S.4.4c — Using a language reference

S.7.x — Chapter 7 summary and quiz

Quick review

std::string offers an easy and safe way to deal with text strings. String literals are always placed between double quotes.

Enumerated types let us define our own type where all of the possible values are enumerated. These are great for categorizing things.

Enum classes work like enums but offer more type safety . . . → Read More: S.7.x — Chapter 7 summary and quiz

6.17 — Unnamed and inline namespaces

C++ supports two permutations on regular namespaces that are worth at least knowing about. We won’t build on these, so consider this lesson optional for now.

Unnamed (anonymous) namespaces

An unnamed namespace (also called an anonymous namespace) is a namespace that is defined without a name, like so:

This prints:

. . . → Read More: 6.17 — Unnamed and inline namespaces

6.5 — Variable shadowing (name hiding)

Each block defines its own scope region. So what happens when we have a variable inside a nested block that has the same name as a variable in an outer block? When this happens, the nested variable “hides” the outer variable in areas where they are both in scope. This is called name hiding or . . . → Read More: 6.5 — Variable shadowing (name hiding)

6.8 — Global constants and inline variables

In some applications, certain symbolic constants may need to be used throughout your code (not just in one location). These can include physics or mathematical constants that don’t change (e.g. pi or Avogadro’s number), or application-specific “tuning” values (e.g. friction or gravity coefficients). Instead of redefining these constants in every file that needs them (a . . . → Read More: 6.8 — Global constants and inline variables

6.7 — External linkage

In the prior lesson (6.6 — Internal linkage), we discussed how internal linkage limits the use of an identifier to a single file. In this lesson, we’ll explore the concept of external linkage.

An identifier with external linkage can be seen and used both from the file in which it is defined, and from other . . . → Read More: 6.7 — External linkage

6.6 — Internal linkage

In lesson 6.3 — Local variables, we said, “An identifier’s linkage determines whether other declarations of that name refer to the same object or not”, and we discussed how local variables have no linkage.

Global variable and functions identifiers can have either internal linkage or external linkage. We’ll cover the internal linkage case in this . . . → Read More: 6.6 — Internal linkage

7.16 — Lambda captures

Capture clauses and capture by value

In the previous lesson, we introduced this example:

Now, let’s modify the nut example and let the user pick a substring to search for. This isn’t as intuitive as you might expect.

This code won’t compile. Unlike nested blocks, where any identifier defined in an . . . → Read More: 7.16 — Lambda captures