By Sándor Dargó, senior software engineer at Spotify
This deep dive is adapted from Sándor’s Deep Engineering session, C++26 Beyond the Headlines: What’s Changing for Developers. We’ve edited it lightly for flow and kept it in his words. The code examples come from his slides, and you can watch the full session and download the slides below.
A bug that stops existing
Let’s start with this small function.
const int& f() {
return 42;
}This is a real, old bug. You return a reference to a temporary, and that dangling reference is a crash waiting to happen somewhere. Before C++26, this compiles. Well, it compiles with a warning if you’re lucky and you use good compiler settings, and not everyone does. Now it’s not a question of compiler settings anymore. C++26 makes sure this doesn’t compile.
No reflection. No contracts. Just a bug that stops existing.
In my opinion, that is the real story of C++26, and that’s what this piece is about: the smaller, sometimes not so small, changes that shape how we see C++.
I’m not going to get into the difficult moments C++26 went through over the last few weeks. But based on the latest news, for example on Herb Sutter’s blog, we can be optimistic that there is going to be something we call C++26. Whenever it’s officially standardized, these features are worth talking about.
Editor’s note: at the November 2026 meeting in Búzios, the committee completed the remaining technical work on C++26 and kept contracts in. The draft now goes to a second international ballot. Herb Sutter’s trip report has the details.
What you’ve heard about C++26
What you’ve heard about C++26 so far is probably one of three features.
Reflection:
std::meta, splicing, compile-time introspection.Contracts: preconditions, postconditions, assertions.
Senders/receivers: structured async execution.
They’re real and transformative, and they’re covered in dozens of other talks, so I won’t cover them here. If you want to go deeper on reflection, Lieven De Cock is running a hands-on C++ Reflection in Practice workshop with Deep Engineering on 10 December.
🔥 Upcoming Deep Engineering events
Join engineers, architects and technical leaders for live sessions on the systems and practices shaping modern software engineering.
📅 Sat 5 Dec: From One GPU to Thousands: Engineering Distributed AI Systems Free
📅 Sun 13 Dec: Architecting Domain-Driven IDPs for the Agentic Era
📅 Wed 20 Jan: Beyond main.cpp: Building a Maintainable C++ Project
📅 Sat 23 Jan: Low-Latency C++ for High-Frequency Trading (HFT)
The big features change what’s possible. The small ones change what’s practical. I’m going to focus on the small ones, grouped into five themes:
Compile-time expansion:
constexprkeeps growing.Clearer correctness: redefining “wrong code.”
Safety via library: hardening the standard library.
Everyday expressiveness: fixing long-standing pain points.
Freestanding: C++ in more environments.
The fourth part is the longest. It covers all those small changes that fix the pain points we deal with while coding, or while reviewing our agents’ code.
I. Compile-time expansion
I have to admit this is the part I’m most afraid of, because I have to say constexpr so many times, and it’s hard to pronounce. But let’s look at how it has evolved over the last fifteen years or so.
It was introduced in C++11, and at first you couldn’t really do anything in a constexpr function. You could return literal types, and that was it. C++14 gave us loops and local variables, so it was already more useful. C++17 brought the compile-time if, so a function could go in different directions depending on whether we’re dealing with a constant expression or not, and we could create constexpr lambdas as well.
C++20 gave us even more: allocations at compile time, and with that, std::string and std::vector in constexpr code. They can’t survive compile time; they can’t cross into the runtime part of C++. But within our constexpr functions, we could already use them for calculations and logic. C++23 added more containers and static_assert improvements. And with C++26 we’re getting exception handling at compile time, placement new, virtual inheritance, structured bindings, and much more of the library.
Before C++26: exceptions stop constant evaluation
A constexpr function could already contain a throw. Take this simple factorial:
constexpr int factorial(int n) {
if (n < 0) throw std::invalid_argument("don't be negative");
int result = 1;
for (int i = 2; i <= n; ++i) {
result *= i;
}
return result;
}
static_assert(factorial(5) == 120); // already OK before C++26
// constexpr int bad = factorial(-1);
// error: expression '<throw-expression>' is not a constant expressionYou could evaluate this at compile time before C++26, as long as the function didn’t throw. Call it with a negative number at compile time and you got a compilation error saying the throw expression is not a constant expression. It didn’t work even if a surrounding catch would have handled it.
C++26: throw and catch at compile time
This is changing with C++26, because you can use both throw and catch at compile time. With the same factorial:
int x = factorial(-1); // runtime: throws
constexpr int y = factorial(-1); // compile-time: uncaught exceptionAt runtime, the throw is just a normal exception, and nothing changes there. At compile time, if the exception isn’t caught, you get a compilation error with the message you defined:
error: uncaught exception of type
'std::invalid_argument'; 'what()': 'don't be negative'We all know C++ isn’t famous for friendly compiler errors. That has changed a lot and is still improving, and this is one of the examples where you can see it. And if a catch handles the exception during constant evaluation, evaluation simply continues, something that didn’t work before.
What else became constexpr in C++26?
On the language side:
Placement new: more flexible initialization at compile time.
Casting from
void*: this enables furtherconstexprwork instd::format,std::functionandstd::any.Structured bindings: they received quite a few improvements, which we’ll look at later, but interestingly you couldn’t declare them
constexpr. Now you can.
On the library side, I can’t even list everything that became constexpr:
<cmath>and<complex>: floating-point math at compile time.std::stable_sort,std::stable_partitionandstd::inplace_merge.All the standard containers, not just
vectorandstringanymore.std::constant_wrapper: pass compile-time constants as regular function arguments.
If you want to go deeper into this topic, I highly recommend Hana Dusíková’s recent talks.
To recap: now that we can use both throw and catch in constexpr code, we don’t need separate error handling for runtime and compile-time code, at least in more cases than before. Metaprogramming gets simpler, because you can use the patterns you’re used to instead of strange, hard-to-read tricks. Handled exceptions let compile-time evaluation recover and continue. And the distinction between runtime C++ and compile-time C++ is slowly disappearing. The mental model is just “write C++.”
II. Clearer correctness
C++26 redefines the correctness model. But first, why is that necessary?
The problem with undefined behavior
Until today, many programming errors simply resulted in undefined behavior. The compiler can assume undefined behavior doesn’t happen, and because of that, anything can go wrong. As we like to say, it could even delete everything on your hard drive. Usually that’s not the case, luckily, but nasal demons can appear, and compilers have no obligation to diagnose undefined behavior.
The C++ correctness model gave us no middle ground between correct code and “all bets are off.” So what does it even mean to write safe code? That’s a difficult question, but Dave Abrahams and Sean Parent gave this answer:
“A safe operation is one that cannot cause undefined behaviour.”
Dave Abrahams and Sean Parent
By that definition, it’s way too easy to write unsafe C++, because so many common mistakes are just undefined behavior. An off-by-one access past the end of a container is enough. Of course, if you write good, correct C++, you won’t hit most of these errors. But they’re there, because we don’t write good code all the time.
C++26 offers a few different answers.
The simplest fix: make it ill-formed
Some undefined behavior in C++26 simply becomes a compile error. We already saw the first example at the start.
// P2748R5: returned reference bound to temporary
const int& f() {
return 42; // C++23: UB — C++26: ill-formed
}
// P3144R2: deleting incomplete types
struct Widget; // forward declaration only
void cleanup(Widget* p) {
delete p; // C++23: UB — C++26: ill-formed
}Deleting an incomplete type was undefined behavior up to and including C++23. In C++26 it’s ill-formed. The compiler just rejects code it should probably have rejected a long time ago.
Compiler support: GCC 15 · Clang 19 (returned reference already enforced in GCC 14)
Introducing: erroneous behavior
That’s not the only answer C++26 gives. The other is erroneous behavior, a new category between defined and undefined behavior. Compiler support isn’t great yet, so we’ll see exactly how it works in practice, but it’s already worth talking about.
int x; // C++23: indeterminate value
// C++26: erroneous value
int y = x; // C++23: undefined behavior
// C++26: erroneous behaviorAssume x is a local variable here. Up to and including C++23, it has an indeterminate value; it’s not initialized. C++26 says it has an erroneous value. So if you assign that x to another local variable, you used to get undefined behavior, and now you get erroneous behavior.
So what’s really the difference?
Defined behavior: the compiler doesn’t get to eliminate anything, it doesn’t need to diagnose anything, and the outcome is fully specified.
Undefined behavior: the compiler may eliminate anything on that code path, it doesn’t have to diagnose it (and in most cases it doesn’t), and the outcome isn’t constrained at all.
Erroneous behavior: the compiler can’t eliminate the code as if it never happens. Diagnosis isn’t mandated by the standard, but implementations are encouraged to diagnose it. And the outcome is constrained.
The program is still wrong, but the immediate read is bounded. Not the operations that follow.
Compiler support: GCC 16
Why not just define it?
You could say, let’s just define the value of that x. Let’s zero-initialize everything!
First, that has a performance cost. Mandatory initialization may be only a few cycles, but in hot loops it adds up quickly, and one of the principles of C++ is that you don’t pay for what you don’t use. Second, zero-initializing everything can hide bugs, because zero might be a valid value, and the bug just becomes silent.
Erroneous behavior is the middle ground. Implementations choose the trade-off between the cost they impose on you and how much diagnosis they provide. Diagnosis is encouraged, and wrong code stays visibly wrong.
Indeterminate values in C++26
C++26 gives us clearer rules for what happens with uninitialized data:
unsigned char buf[16]; // erroneous values
memcpy(dst, buf, 16); // no erroneous behavior — values propagate to dst
struct S { int a; int b; };
S s;
s.a = 42;
int x = s.b; // erroneous behaviorThe buffer on the first line holds erroneous values because we declared it but didn’t initialize it. Copying it with memcpy isn’t erroneous behavior by itself; the erroneous values just propagate to dst. But reading an uninitialized member directly and assigning it to another variable is erroneous behavior.
What about variables you intentionally leave uninitialized? You might have good reasons for that, so C++26 brings the new [[indeterminate]] attribute as an opt-in:
int x [[indeterminate]]; // opt-in: reading x before init is still UBYou’re saying: here is an uninitialized x, and its value is indeterminate on purpose. That’s why wrong code becomes easy to identify. You make it explicit in your code which variables you leave uninitialized, and once you declare a variable like this, it’s your responsibility to initialize it before you use it. It’s explicit, auditable, and your responsibility.
To recap: “wrong” is no longer all-or-nothing in the C++ correctness model. There’s erroneous behavior between defined and undefined. Implementations can and will help us, at a cost they choose. We don’t really have compiler support yet, but I’m sure it will arrive soon, and based on the standard’s recommendations, we’ll certainly get improved diagnostics for this kind of wrong code.
And this is just the beginning. We’ve seen with many modern C++ features that the first standard version introduces the foundations, and more arrives later. It happened with constexpr, and it’s going to be pretty much the same with reflection: you get a minimum viable product, and it grows. I think that’s the intention of the authors of erroneous behavior as well.
III. Library hardening
So far we’ve talked about correctness and the trust we have in C++ code. Now think about the trust model of the standard library:
std::vector<int> v = {1, 2, 3};
v[5]; // Your problem. UB. Good luck.Historically, the standard library assumed correct usage. A vector of three items, and you try to access the sixth element: that’s your problem. The preconditions aren’t expressed in code, but they’re clearly communicated through the documentation. Violate them, and that’s on you.
C++26’s answer is library hardening. A hardened implementation checks selected preconditions at runtime, and a violation stops the program instead of corrupting it.
What gets hardened?
Not everything. Covering everything was an explicit non-goal of library hardening. You can’t cover everything, it would be too costly, and then people wouldn’t use it. So the authors deliberately focused on memory-safety preconditions only:
v[5]; // bounds check
v.front(); // empty check
*opt; // has_value check
span.first(n); // count in range
expected.error(); // !has_value check
mdspan[i, j, k]; // all indices in extentsThese checks cover vector, array, deque, list, forward_list, string, span, string_view, optional, expected, mdspan, bitset and valarray.
This is exactly what the authors wrote in the proposal:
“In our experience in libc++, a small set of checks that is widely used delivers far more value than a more extensive set of checks that is only enabled by select few users.” P3471R4, Standard library hardening
Hardening isn’t new, now it’s standard
Hardening already existed. Vendors have shipped hardening modes for years; it just wasn’t standardized. What’s different now is that P3471R4 brings it into the standard. In the standard, it’s a single switch: an implementation is hardened or it isn’t.
In practice, vendors offer layers. Here’s what libc++ offers:
None: checks nothing, zero overhead.
Fast: bounds, null and basic preconditions, with minimal overhead. This is what the standard now basically covers, and you’re encouraged to ship to production with these checks on.
Extensive: adds iterator and algorithmic preconditions, with moderate overhead.
Debug: checks everything, including heuristics, with significant overhead.
The extra layers aren’t in the standard, at least not yet. You usually enable hardening with a compiler flag such as -fhardened or -D_LIBCPP_HARDENING_MODE=..., but which flag to use isn’t standardized either. The key constraint is that you cannot ignore a hardened precondition violation, and that clearly increases the safety of our code.
Library hardening might also become the first production use of C++26 contracts. That was the goal. If contracts get accepted by the national bodies in the next ballot round, we can safely say library hardening will be one of the first users of C++26 contracts.
Compiler support: libstdc++ 15 (partial) · MSVC STL 19.44+ (partial) · libc++ vendor hardening since LLVM 18
The proof: Google’s production data
You might ask whether this works. There is proof, and it comes from Google’s production data. Google enabled hardened libc++ across hundreds of millions of lines of C++ and shared the metrics in a blog post.
By turning on library hardening, they found more than a thousand bugs, including security-critical ones. They project these checks will prevent 1,000 to 2,000 bugs a year. After they fixed the bugs that hardening surfaced, their segfault rate dropped by 30%, which is quite nice. And the performance overhead was really small: 0.30% on average.
0.30%: how?
0.30% is really low. How is that even possible?
Redundant checks are optimized away. The compiler is smart. It won’t test the same bounds again and again once it can prove they’re safe.
Each check is O(1). With this initial set of checks, it’s a comparison and a branch, nothing more.
Profile-guided optimization reduces the overhead further. Google kept going until they were happy with the level of overhead.
One fix made a measurable difference. Google removed one unnecessary check, which dropped the overhead from 0.35% to 0.30%.
Three approaches, one direction
All the approaches we’ve discussed so far serve the same goal: shrinking the amount of undefined behavior in our code.
Ill-formed: the compiler rejects code that was always wrong (P2748, P3144).
Erroneous behavior: the language reclassifies some undefined behavior as bounded.
Library hardening: a hardened standard library catches misuse at runtime through precondition checks.
Different mechanisms, same direction: wrong code should be diagnosable, not a license for the compiler to do anything.
The takeaway on library hardening is that it gives you earlier failures. You catch bugs at the point of misuse, not three stack frames later. It’s production-viable: if Google can use it, anyone can. It’s portable, with one standard framework instead of vendor-specific hacks. And again, it’s a minimum viable product, the foundation for more precondition checks to come later.
As I wrote on my blog, library hardening is one of those features that makes you wonder why it wasn’t standardized sooner. But let’s not dwell on that. Let’s be happy it’s in the standard now.
IV. Everyday expressiveness
C++26 simplifies our code a lot. I think that still matters in an age when most of us write code with AI, because we still have to read code. If we can read code more easily, and if the agents can read code more easily, that matters.
Function wrappers: the landscape before C++26
Before C++26, we had raw function pointers, which hold no state, and std::function, which allocates, copies, and owns the callable it stores.
// Raw function pointer — no state
void (*callback)(int);
// std::function — allocates, copies, owns
std::function<void(int)> f;C++23 added std::move_only_function, which is owning, move-only as the name implies, and const-correct. We’ll come back to the const-correct part.
But what about something non-owning, non-allocating and type-erased? Or something owning and copyable that, unlike std::function, is also const-correct? There were gaps in the taxonomy.
std::function_ref
The first thing C++26 provides here is std::function_ref, a non-owning, non-allocating callable reference:
int apply(std::function_ref<int(int)> f, int x) {
return f(x);
}
auto lambda = [](int x) { return x * 2; };
apply(lambda, 21); // No allocation. No copy.It’s like a reference to any callable, with zero overhead beyond the indirect call. It’s perfect for callbacks you don’t need to store. Here, apply just takes a function reference and calls it with the parameters we pass. We don’t need std::function. We don’t need std::move_only_function. This is enough.
Compiler support: GCC 16 · libc++ 24 (upcoming)
std::copyable_function
We also get std::copyable_function, which is owning, type-erased, and guaranteed to be copyable:
std::copyable_function<int(int)> make_adder(int n) {
return [n](int x) { return x + n; };
}
auto f = make_adder(10);
auto g = f; // Always works. Guaranteed.And unlike std::function, it’s const-correct: its call operator respects const.
Compiler support: GCC 16
The std::function const bug
I’ve mentioned const-correctness twice now, so let’s see what it really means.
// https://godbolt.org/z/nKnajhzsh
const std::function<int()> f = [n = 0]() mutable { return ++n; };
f(); // Compiles! Mutates through a const object.We have a const std::function that takes any callable returning an int with no parameters, and we give it a mutable lambda that changes n. Then we invoke f, and it compiles. It mutates n through a const object. That’s probably not what people would expect, but std::function::operator() is always const, even when the wrapped callable’s call operator, like this lambda’s, is not. The const doesn’t propagate, and the wrapper silently allows mutation.
With std::copyable_function, that’s not the case:
const std::copyable_function<int()> g = [n = 0]() mutable { return ++n; };
g(); // Compile error: non-const operator() called on a const wrapperSame signature, same mutable lambda, and invoking g gives you a compiler error, because you’re calling a non-const call operator on a const wrapper. Finally, this is done right in C++26, because const-ness is part of the signature. If you want a wrapper you can call through const, use a const signature: std::copyable_function<int() const> is callable through const, and it rejects the mutable lambda one level earlier, at construction.
The callable taxonomy in C++26
After C++26, we still have function pointers. We still have std::function, which owns, may allocate, and can be copied, but isn’t const-correct. I think in new code, we can basically forget about std::function, because we have three better options. Use std::function_ref when you don’t need to store the callable at all and just need a reference. Then choose std::move_only_function or std::copyable_function depending on whether you need copyability. Either way, you get const-correctness.
Pick the right tool for the job.
The const bug, part two
That wasn’t the only const bug C++26 fixes. Well, sort of fixes: the old code isn’t fixed, but you get options you didn’t have before. The same problem hides in composite design, for example in the Pimpl idiom, because pointer members don’t propagate const:
class Widget {
std::unique_ptr<Impl> _pimpl;
public:
void inspect() const {
_pimpl->mutate(); // compiles — const doesn't propagate through the pointer
}
};
const Widget w{/* ... */};
w.inspect(); // mutates the Impl behind our backInside a const member function, _pimpl is a const unique_ptr. You can’t reseat it, but the Impl it points to is still mutable. In many cases that’s not what you want; you’d want that const-ness to carry through, and with unique_ptr that’s a limitation.
C++26 gives us std::indirect, and with it you can get this right very easily:
class Widget {
std::indirect<Impl> _pimpl;
public:
void inspect() const {
_pimpl->mutate(); // does NOT compile — const propagates
}
};
const Widget w{/* ... */};
w.inspect(); // correctly rejectedInstead of unique_ptr, you use std::indirect<Impl>, and a mutating call from a const member function is rejected at compile time. A const Widget gives you a const Impl. You also get deep copies on assignment, so you don’t need all the special member functions you had to write with unique_ptr. No custom copy constructor is needed; std::indirect covers it. (In a real Pimpl, where Impl is incomplete in the header, you still declare those members and = default them in the .cpp file.)
For class hierarchies, there’s std::polymorphic<Base>. Copies preserve the dynamic type. You don’t have to implement clone(), and you get no slicing.
Compiler support: GCC 16
std::optional<T&>: an existing object, or nothing
Before C++26, std::optional could only hold a T; you couldn’t use references. Now std::optional<T&> is possible (P2988):
std::optional<User&> find_user(std::span<User> users, int id) {
for (auto& user : users)
if (user.id == id) return user;
return std::nullopt;
}
if (auto user = find_user(users, 42)) {
user->active = true; // updates the original User
}It borrows the object: no copy, no change of ownership. It has the same optional operations you’re used to, like has_value(), transform() and and_then(). It does not extend the object’s lifetime, which is important to keep in mind. And you can provide read-only access with std::optional<const User&>. Much like with smart pointers, the const is on the referenced object, not on the wrapper.
Assignment rebinds:
int alice_score = 10, bob_score = 20;
std::optional<int&> score = alice_score;
score = bob_score; // now refers to bob_score
// alice_score is still 10; bob_score is still 20
*score = 99; // writes through the reference
// alice_score is still 10; bob_score is now 99score first refers to alice_score. Then we assign bob_score, and now score refers to bob_score. When we write through the optional reference, we don’t touch alice_score; we only update bob_score. So score = ... changes which object is referenced, and *score = ... changes the referenced object. You can also clear it with score = std::nullopt. The objects aren’t affected; only score changes, and it no longer refers to anything.
std::optional is now also a range
std::optional got another improvement: it’s now also a range. An engaged optional has one element, and an empty one has none. That’s useful, because you can use optionals in ranges pipelines in ways you couldn’t before.
std::optional<int> parse_number(std::string_view text);
std::string_view inputs[] = {"42", "oops", "7"};
auto numbers = inputs
| std::views::transform(parse_number)
| std::views::join;
for (int n : numbers)
std::cout << n << ' '; // 42 7transform produces optionals, and join flattens them. Empty optionals contribute no elements. It works with both optional<T> and optional<T&>, so it’s pretty complete.
List-initialization for algorithms
std::vector<std::complex<double>> values;
// Already worked
values.push_back({1, 2});
// Before C++26: spell out the value type
std::ranges::find(values, std::complex<double>{1, 2});
// C++26: now works too
std::ranges::find(values, {1, 2});With a vector of complex numbers, you could already list-initialize the element in push_back. But inside an algorithm, you had to spell out the value type, because the compiler couldn’t deduce it. In C++26, the algorithm can get the value type from the range. It also works with selected classic algorithms and operations such as std::erase. It simplifies your code, though you might argue it actually decreases readability. It’s an option; I probably wouldn’t use it.
std::format in C++26
The missing piece in std::format was dynamic format strings (P2918 and P3953):
// C++20/23: format string must be a compile-time constant
std::format("{} logged in", username); // OK
// C++26: dynamic format strings
std::string fmt = load_from_config("greeting");
std::format(std::dynamic_format(fmt), username);You can load a format string from configuration or build it up piece by piece, and use it instead of having to fix it at compile time. That’s a nice addition.
We also got better pointer formatting (P2510): std::format("{:018}", ptr) with zero-padding and case control. And std::to_string was fixed (P2587): to_string(0.42) now returns "0.42", what you’d expect, not the longer and less readable "0.420000".
Structured bindings: three limitations removed
Structured bindings are particularly interesting. C++26 removes three limitations: you can put attributes on individual bindings (P0609R3), you can use them in conditions (P0963R3), and they can introduce parameter packs (P1061).
First, attributes:
auto [x, unused [[maybe_unused]], z] = get_triple();
// Before: [[maybe_unused]] could only be applied to the whole declarationBefore C++26, if you wanted [[maybe_unused]], it applied to all the decomposed parts, so x, unused and z would all have been marked. Now you can annotate individual bindings instead of the whole declaration. It’s also worth mentioning that C++26 makes _ a reusable, implicitly [[maybe_unused]] placeholder (P2169), pretty much like in Python.
Compiler support: GCC 15 · Clang 19
Next, conditions:
if (auto [value, ec] = std::to_chars(buf, end, 42)) {
// decompose AND test in one statement
}
while (auto [header, body] = receive_packet()) {
process(header, body);
}Interestingly, we couldn’t do this before. You don’t have to declare the value and the error code outside the condition anymore; you do it right there. No temporary variable just to check a status code. It decreases the scope of the variables, keeping everything safer and tighter. You can use it in the condition of a while loop, too.
Compiler support: GCC 15 · Clang 21
And finally, packs:
template <typename T>
void print_fields(const T& obj) {
auto [... fields] = obj;
(std::cout << ... << fields);
}
// Or capture some, pack the rest:
auto [first, ...rest] = get_tuple();Structured bindings can now introduce parameter packs. This replaces some, well, not-so-nice metaprogramming hacks for decomposing aggregates, and it pairs naturally with pack indexing (rest...[0]). In C++26, binding packs are allowed in templated code, like print_fields above. Using them in ordinary, non-template code is a boundary that’s still being pushed.
Compiler support: GCC 16 · Clang 21
Pack indexing
Here’s the old way to get the Nth type in a pack:
template<std::size_t N, typename T, typename... Ts>
struct nth_type : nth_type<N - 1, Ts...> {};
template<typename T, typename... Ts>
struct nth_type<0, T, Ts...> {
using type = T;
};
using third = nth_type<2, int, double, char, bool>::type;I know this is probably overly complex, and you have other options as well. But I wanted to make a point: getting an element of a pack was real work, both for the programmer and for the compiler. With C++26, you just index the pack:
template<typename... Ts>
using third = Ts...[2];It works for type packs and value packs: args...[0], args...[sizeof...(Ts) - 1]. It’s a nice, neat feature. Templates get simpler, because direct access replaces recursion. Compilation gets faster, because there are fewer template instantiations, so it’s not just better for the reader but for the compiler as well. The intent is obvious. And it makes variadic templates more approachable for everyone.
Compiler support: GCC 15 · Clang 19
= delete(”reason”)
Another nice addition that improves compiler error messages is = delete with a reason. Before, the compiler could tell you what, but not why:
error: use of deleted function 'NonCopyable::NonCopyable(const NonCopyable&)'With C++26, the author can explain the intent of the deletion:
NonCopyable(const NonCopyable&)
= delete("Manages unique resources; use move instead.");error: use of deleted function 'NonCopyable::NonCopyable(const NonCopyable&)'
"Manages unique resources; use move instead."You can write anything you want there, and it appears in the compiler’s error message. This isn’t something we haven’t seen before. It follows the same pattern as [[deprecated]], [[nodiscard]], and static_assert, which can now get nicer, user-generated messages, also a C++26 change.
Compiler support: GCC 15 · Clang 19
V. Freestanding
Last but not least, freestanding. If you haven’t heard about it, freestanding is a subset of C++ that works without an operating system. Typically, you don’t have <iostream>, you don’t have <filesystem>, and you have no exceptions. It’s used in embedded systems, kernels, bootloaders and firmware. Historically, very little of the standard library was available there.
That’s changing with C++26. A lot of standard library types are now available in freestanding, at least the parts that don’t throw, since throwing is something we don’t have in freestanding. C++26 adds <optional>, <expected>, <variant>, <string_view>, the non-allocating subset of <algorithm>, and <inplace_vector>, on top of headers like <utility>, <tuple> and <type_traits> that were already there.
// embedded codebase, pre-C++26
struct MaybeConfig { bool has; Config value; }; // hand-rolled
// C++26 freestanding
std::optional<Config> load_config(); // just C++Why is this good? Because you don’t have to build your own optional types, your own expected types, in every codebase. You can just use standard C++. The principle: if it doesn’t need an OS, it should be freestanding.
Compiler support: GCC 14 · MSVC 19.42
std::inplace_vector: no heap required
C++26 also brings a new container, std::inplace_vector. Unlike std::vector, it requires no heap. It has a fixed capacity and provides the normal std::vector API we’re used to.
// hand-rolled
struct SensorLog { int buf[16]; int count; };
void push(SensorLog& s, int v) { s.buf[s.count++] = v; } // no bounds check
// Boost — better, but a dependency
boost::container::static_vector<int, 16> log;
// C++26 — standardized, constexpr, freestanding
std::inplace_vector<int, 16> log;
log.push_back(reading); // throws std::bad_alloc if fullBefore, if you wanted these capabilities, for example in freestanding, you had to build your own type, or maybe use Boost’s static_vector. std::inplace_vector is basically the standardized static_vector, but Boost introduces a dependency, which might or might not be fine for your use case. In C++26, you get it in the standard.
On my slides, I said the storage is on the stack, but that wasn’t the best wording. The storage is wherever you declare your inplace_vector. Declare it on the stack, and everything is on the stack. Declare it on the heap, and the storage is on the heap as well. There’s a reason it wasn’t standardized under its Boost name, static_vector: that would have been misleading. What matters for freestanding is that there’s no allocator and no allocation.
If T is trivially copyable, the inplace_vector of T is trivially copyable too. It’s constexpr-friendly, and it’s usable in freestanding. Almost all the parts, I should say, because push_back might throw. This is where all the themes converge.
inplace_vector: three ways to push
There are three ways to add an element to an inplace_vector:
v.push_back(x); // throws std::bad_alloc if full
auto result = v.try_push_back(std::move(s)); // std::optional<T&>
if (!result) {
// s is NOT moved-from — guaranteed
}
v.unchecked_push_back(x); // precondition: size() < capacity()push_backis the safe default operation, but it throws when it would overflow the capacity.try_push_backis there if throwing isn’t acceptable. It returns anoptional<T&>to the inserted element, and an empty optional if the vector is already full.unchecked_push_backdoes no check. It gives you maximum performance, but you get undefined behavior if you violate its precondition and grow the size beyond the capacity.
And yes, there’s emplace_back as well. It just wouldn’t fit on the slide.
Container support: GCC 15 · MSVC 19.43; check P3981 support for the new return type
To recap freestanding: less reinventing of the wheel, because you use std::optional and std::inplace_vector instead of building your own. More portable code across many platforms. Ecosystem alignment, because libraries can depend on standard types. And the same vocabulary everywhere: hosted and embedded speak the same C++.
Putting it together
I didn’t want to give a full feature list of C++26; that would take a day, not an hour. I wanted to talk about the direction, because I think these five themes reinforce each other:
Compile-time expansion plus correctness: you catch errors before they reach runtime.
Correctness plus hardening: you catch the rest at runtime.
Hardening plus expressiveness: you can build safer APIs that more people want to use, and can use safely.
Expressiveness plus freestanding: C++26 brings modern C++ everywhere.
It’s not a feature list. It’s a direction: make correct C++ easier to write, and incorrect C++ easier to catch.
What to try first
When you get the chance to try a C++26 compiler, here’s where I’d start:
Recompile with
-std=c++26. Dangling references and incomplete-type deletes become compile errors, basically for free.Turn on the hardening flags in your CI today. I think they might even be on by default with C++26, but check your vendor. C++26 isn’t required here; it will probably work on your current codebase already.
Try
constexprexceptions. Reuse your throw-and-catch error handling at both compile time and runtime, without making distinctions.Use
std::function_ref. Replace your next callback parameter wherever you can. It’s cheaper, it’s more expressive, and it’s just such a handy addition.Use pack indexing. It will simplify your variadic templates right away.
Sándor Dargó is a senior software engineer at Spotify and the author of several C++ books. He writes about C++, including C++26 features one by one, at sandordargo.com. Connect with him on LinkedIn.











