`default` in C++: a defaulted destructor vs. a `switch` label
`~T() = default;` asks the compiler to define a destructor by the language rules. `default:` marks where a `switch` starts executing when no `case` matches.
CKTIS / C++
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
`~T() = default;` asks the compiler to define a destructor by the language rules. `default:` marks where a `switch` starts executing when no `case` matches.
The basic guarantee permits partial changes that leave valid state. The strong guarantee leaves no observable change on exception. The no-throw guarantee prevents exceptions from reaching the caller.
A compile-time flag selects a program variant when you build it. A runtime flag changes the behavior of an already-built program.
Append `f` or `F` to make a floating-point literal a `float` rather than the default `double`. This affects type deduction and overload resolution.
With `F` deduced, `F&&` can bind to either an lvalue or an rvalue. A direct call `f()` treats the callable as an lvalue; `std::forward<F>(f)` passes it on as an lvalue or rvalue according to the argument.
Search an ordered associative container with a different type from its key, without constructing a temporary key. Learn why `std::less<>` enables the lookup overloads and why mixed comparisons must agree with the key order.
In C++23, `return a;` can move from a by-value parameter. This is not NRVO: the parameter is a separate object from the result.
Define an inline variable with external linkage in a shared header to give multiple translation units the same object. Compare it with an ordinary namespace-scope `const` that gives each translation unit its own object.
Work out the type used for arithmetic on `std::uint8_t` and `std::uint16_t`, and distinguish it from the destination type and from how a value is printed.
The built-in suffix `ULL` gives a representable integer literal the type `unsigned long long`. It is not a literal operator or part of a number's sign.
Learn when a vector mutation invalidates iterators, references, and pointers, including the past-the-end iterator, and how to use a std::find_if result safely.
In `+hardPass`, unary `+` makes a non-generic captureless lambda use its implicit conversion to a function pointer. Changing the argument type can change which overload is selected.
`score =+ delta` assigns the result of unary `+delta`. To add `delta` to the current value of `score` and store the result, use `score += delta`.
Declare names for tuple elements with structured bindings. Learn when they refer to a copy or the original, and how they differ from `std::get` and `std::tie`.
`[&]` sets the by-reference capture default: the lambda uses the original local objects rather than copies, but it does not keep those objects alive.
A declarator’s `&` forms an lvalue reference type. Learn what it can bind to, when you can write through it, and how to avoid dangling references.
`R&` aliases an existing object. Assigning through it modifies that object, and returning `R&` lets the caller keep referring to the same object without making a copy.
`int* (&items)[3]` refers to the entire array of three pointers. The bound stays part of the type, and a cleanup guard can update the original pointer slots.
`= delete` forbids use of a specific function or constructor without removing it from the overload set. It does not destroy an object or release memory.
A non-type template parameter takes a value rather than a type. See how `std::size_t Size` fixes an array’s extent and how the compiler deduces it from function arguments.
Storage can outlast the object it holds. Lifetime determines when an object exists, while strict aliasing determines which expression types may access its stored value.
A pool reuses individual slots; a monotonic arena reclaims storage in bulk. A generation-tagged handle distinguishes a new object from an old one at the same address.
Declare custom suffixes `_KiB`, `_MiB`, and `_pct`. See how the literal's form selects an operator and how built-in `ULL` and unary minus differ from a custom suffix.
Use `<<` to write values to an output stream or change its formatting. The operand types distinguish stream insertion from the built-in left shift.