# C++ Stories

Recent content on C++ Stories

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## C++26 Contracts: Introduction to Preconditions and Postconditions

DevFeed: [C++26 Contracts: Introduction to Preconditions and Postconditions](<https://devfeed.tech/articles/c-26-contracts-introduction-to-preconditions-and-postconditions-84965.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2026/cpp26_contracts/>)

Published: 2026-10-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [data type](<https://devfeed.tech/topics/data-type.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-26](<https://devfeed.tech/tags/c-plus-plus-26.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [contracts](<https://devfeed.tech/tags/contracts.md>), [cpp](<https://devfeed.tech/tags/cpp.md>), [hardening](<https://devfeed.tech/tags/hardening.md>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

This tutorial explains C++26 contracts through preconditions, postconditions and assertions inside functions. It compares contracts with `assert`, discusses declaration placement and evaluation semantics, and stresses that contracts are not substitutes for input validation or required program logic.

### Source excerpt

In the article about Standard Library hardening, we looked at checks for invalid Standard Library container access and other broken preconditions. I mentioned that those requirements are expressed in terms of "contracts". But what about our code? In this post, we'll explore contracts from C++26. We'll start with a simple cassert, move the requirement into the function itself, and see how to check results. We'll also look at declarations and definitions, compiler options, and a few details that can surprise you. Starting with an Assertion Let's start with a small example: A header file first: // foo.h #include <vector> int get_value(const std::vector<int>& values, std::size_t index); And the implementation: // foo.cpp #include "foo.h" // our function declaration... #include <cassert> int get_value(const std::vector<int>& values, std::size_t index) { assert(index < values.size()); return values[index]; } The function expects a valid index. If the condition is false, assert prints a diagnostic message and terminates the program. However, this only happens when assertions are enabled. Defining NDEBUG disables the check and basically removes the check from the code. What are the issues with this simple approach? The requirement lives inside the implementation. Somebody reading only the declaration sees a vector and an index, without the relationship between them. Adding a Precondition With C++26 contracts, we can move that requirement from an assertion inside the function body to the function itself: int get_value(const std::vector<int>& values, std::size_t index) pre(index < values.size()) { return values[index]; } Notice the new pre(...) syntax after the parameter list. It introduces a precondition assertion: a condition expected to hold when entering the function. What's more, we can add this precondition to the declaration: int get_value(const std::vector<int>& values, std::size_t index) pre(index < values.size()); The feature was introduced through P2900, Contracts

## Using C++17 std::optional

DevFeed: [Using C++17 std::optional](<https://devfeed.tech/articles/using-c-17-std-optional-61110.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2018/05/using-optional/>)

Published: 2026-09-28T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [Programming](<https://devfeed.tech/topics/programming.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [union types](<https://devfeed.tech/topics/union-types.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-20](<https://devfeed.tech/tags/c-plus-plus-20.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [c-plus-plus-26](<https://devfeed.tech/tags/c-plus-plus-26.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [null](<https://devfeed.tech/tags/null.md>), [programming](<https://devfeed.tech/tags/programming.md>), [rust](<https://devfeed.tech/tags/rust.md>), [type-safety](<https://devfeed.tech/tags/type-safety.md>)

### AI overview

This tutorial explains std::optional, a C++17 value type that represents a value that may be absent. It discusses its type safety, memory behavior, and uses such as nullable values, computation results, lazy resource loading, and optional function parameters.

### Source excerpt

Let's take a pair of two types <YourType, bool> - what can you do with such composition? In this article, I'll describe std::optional - a helper "vocabulary" type added in C++17. It's a wrapper that either contains a value of your type or is empty. Let's see where it can be useful and how you can use it. Updated in September 2026 with C++20, C++23, and C++26 changes. Intro By adding the boolean flag to other types, you can achieve a thing called "nullable types". As mentioned, the flag is used to indicate whether the value is available or not. Such wrapper represents an object that might be empty in an expressive way (so not via comments :)) While you can achieve "null-ability" by using unique values (-1, infinity, nullptr), it's not as clear as the separate wrapper type. Alternatively, you could even use std::unique_ptr<Type> and treat the empty pointer as not initialized - this works, but comes with the cost of allocating memory for the object. Optional types - that come from functional programming world - bring type safety and expressiveness. Most of other languages have something similar: for example std::option in Rust, Optional<T> in Java, Data.Maybe in Haskell. std::optional was added in C++17 and brings a lot of experience from boost::optional that was available for many years. Since C++17 you can just #include <optional> and use the type. Such wrapper is still a value type (so you can copy it, via deep copy). What's more, std::optional doesn't need to allocate any memory on the free store. std::optional is a part of C++ vocabulary types along with std::any, std::variant and std::string_view. When to use Usually, you can use an optional wrapper in the following scenarios: If you want to represent a nullable type nicely. Rather than using unique values (like -1, nullptr, NO_VALUE or something) For example, user's middle name is optional. You could assume that an empty string would work here, but knowing if a user entered something or not might be important. W

## C++26: Standard Library Hardening Experiments

DevFeed: [C++26: Standard Library Hardening Experiments](<https://devfeed.tech/articles/c-26-standard-library-hardening-experiments-53318.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2026/hardening-experiments/>)

Published: 2026-08-30T00:00:00Z

Content type: article

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [standard](<https://devfeed.tech/topics/standard.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [interface](<https://devfeed.tech/topics/interface.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [contracts](<https://devfeed.tech/tags/contracts.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [exception](<https://devfeed.tech/tags/exception.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [undefined-behaviour](<https://devfeed.tech/tags/undefined-behaviour.md>)

### AI overview

An explanation of C++26 standard-library hardening, using vector element access to show how hardened implementations turn certain invalid accesses into contract violations with terminating behavior instead of undefined behavior. It distinguishes hardening from bounds-checked access through at() and discusses the relationship to Contracts and exception handling.

### Source excerpt

"Hardening" seems to be a very popular term in the C++ World in 2026. In this article we'll explore what this word means and see some core examples. Can a hardened library make C++ fully safe? Let's find out. The Core Idea When you learned about std::vector you may remember that you can access an element at the i-th position using at least two expressions: std::vector<int> v { 1, 2, 3, 4 }; v[i] = 10; // for some i v.at(j) = 11; // for some j The main difference between those two is that [] is unchecked (and can generate undefined behaviour if you try to access an element which is not there), while .at() may throw std::out_of_range (so it's a well defined behaviour). C++26 Changes In C++26, the Standard introduces the notion of a hardened implementation. Whether a standard-library implementation is hardened, and how that mode is enabled, is implementation-defined. For std::vector<T, Allocator>::operator[](size_type pos): C++ Standard Condition until C++26 If pos < size() is false, the behavior is undefined. since C++26 If pos < size() is false: If the implementation is hardened, a contract violation occurs, If the implementation is not hardened, the behavior is undefined. In other words, if you switch this "hardened" mode you'll get some well specified error/violation rather than just an undefined behaviour. Let's untangle the wording and common questions: For .at() you may get an exception... so why do we need a new alternative? That's fair question. In short at() and [] has different interfaces and performance/error-handling approaches. What's more important you cannot turn exceptions off easily (you can, and std::terminate will be called, but that's not very flexible). So Hardening does not change operator[] into at() - it detects a programming error and terminates instead of allowing memory-unsafe undefined behaviour. "A contract violation occurs" - this is the key thing here. The "hardening" feature is expressed in terms of Contracts that also were accepted into

## Understanding std::counting\_semaphore and std::binary\_semaphore from C++20

DevFeed: [Understanding std::counting\_semaphore and std::binary\_semaphore from C++20](<https://devfeed.tech/articles/understanding-std-counting-semaphore-and-std-binary-semaphore-from-c-20-53319.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2026/semaphore/>)

Published: 2026-08-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [synchronization](<https://devfeed.tech/topics/synchronization.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [mutex](<https://devfeed.tech/tags/mutex.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [synchronization](<https://devfeed.tech/tags/synchronization.md>), [threading](<https://devfeed.tech/tags/threading.md>), [threads](<https://devfeed.tech/tags/threads.md>)

### AI overview

A tutorial on the C++20 counting and binary semaphore types. It explains how counting semaphores limit concurrent work, how binary semaphores signal between threads, and how timed waiting and related operations work.

### Source excerpt

This article explains the two semaphore types introduced in C++20: std::counting_semaphore and std::binary_semaphore. We'll first use a counting semaphore to limit how many threads can operate at the same time. Then we'll use a binary semaphore to send a signal between threads. We'll also look at timed waiting, a small RAII helper, and a few more details. Note: The synchronization features discussed here are available in C++20. The examples use C++23 std::println for cleaner output. Let's go. Basics A mutex works well when only one thread should enter a protected section at a time. But sometimes that limit is too strict. Imagine an application with three database connections. Running only one database operation at a time would waste two of them. On the other hand, allowing any number of threads to start an operation could overload the database. What we need is a limit: three threads may continue, while the others wait. There is another common case. One thread prepares some data, and another thread waits until the data is ready. Semaphores work well for both problems. A lot of multi-threading libraries have semaphores, but it's pretty cool that the C++20 Standard Library now includes them right out of the box. API A counting semaphore is declared as: std::counting_semaphore<LeastMaxValue> The main operations are: Function Description counting_semaphore(desired) Creates a semaphore with the counter set to desired acquire() Decreases the counter, or waits if it is zero release(update) Increases the counter by update; the default is 1 try_acquire() Tries once without waiting try_acquire_for() Waits for a limited duration try_acquire_until() Waits until a given time point max() Returns the largest counter value supported by the implementation std::binary_semaphore is an alias for: std::counting_semaphore<1> It is useful when one outstanding signal is enough. Let's start with the counting version. Limiting concurrency with std::counting_semaphore Suppose we have eight job

## How to join or concat ranges, C++26

DevFeed: [How to join or concat ranges, C++26](<https://devfeed.tech/articles/how-to-join-or-concat-ranges-c-26-53313.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/join_concat_ranges/>)

Published: 2026-05-16T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Collections](<https://devfeed.tech/topics/collections.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [collections](<https://devfeed.tech/tags/collections.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [lazy](<https://devfeed.tech/tags/lazy.md>)

### AI overview

A tutorial comparing C++ range adaptors for concatenating and flattening collections: concat_view from C++26, join_view from C++20, and join_with_view from C++23. It explains their behavior, supported operations, lazy evaluation, and practical examples.

### Source excerpt

Modern C++ continuously improves its range library to provide more expressive, flexible, and efficient ways to manipulate collections. Usually, when you wanted to concatenate or flatten ranges, you'd use raw loops or custom algorithms. With C++'s range adaptors, we now have an elegant and efficient way to process collections lazily without unnecessary allocations. In this post, we will explore three powerful range adaptors introduced in different C++ standards: std::ranges::concat_view (C++26) std::ranges::join_view (C++20) std::ranges::join_with_view (C++23) Let's break down their differences, use cases, and examples. Updated in May 2026: added from_range construction options. std::ranges::concat_view (C++26) The concat_view allows you to concatenate multiple independent ranges into a single sequence. Unlike join_view, it does not require a range of ranges-it simply merges the given ranges sequentially while preserving their structure. In short: Takes multiple independent ranges as arguments. Supports random access if all underlying ranges support it. Allows modification if underlying ranges are writable. Lazy evaluation: No additional memory allocations. See the example: #include <print> #include <ranges> #include <vector> #include <array> int main() { std::vector<std::string> v1{"world", "hi"}; std::vector<std::string> v2 { "abc", "xyz" }; std::string arr[]{"one", "two", "three"}; auto v1_rev = v1 | std::views::reverse; auto concat = std::views::concat(v1_rev, v2, arr); concat[0] = "hello"; // access and write for (auto& elem : concat) std::print("{} ", elem); } See at @Compiler Explorer The output: hello world abc xyz one two three The example below shows how to concatenate three ranges, v1 is reversed and then combined with v2 and arr. Notice that we can also access the value at position 0 and update it. And a bit more complex example: #include <print> #include <ranges> #include <vector> #include <list> #include <string> struct Transaction { std::string type; d

## 15 Different Ways to Filter Containers in Modern C++

DevFeed: [15 Different Ways to Filter Containers in Modern C++](<https://devfeed.tech/articles/15-different-ways-to-filter-containers-in-modern-c-53298.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2021/filter-cpp-containers/>)

Published: 2026-05-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [Code](<https://devfeed.tech/topics/code.md>), [Library](<https://devfeed.tech/topics/library.md>), [implementation](<https://devfeed.tech/topics/implementation.md>)

Tags: [2025](<https://devfeed.tech/tags/2025.md>), [algorithms](<https://devfeed.tech/tags/algorithms.md>), [article](<https://devfeed.tech/tags/article.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [library](<https://devfeed.tech/tags/library.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

### AI overview

A tutorial explores multiple ways to implement a filter function for C++ containers, including raw loops, standard-library algorithms, and modern C++ techniques. The article was updated with additional C++23 techniques.

### Source excerpt

Do you know how many ways we can implement a filter function in C++? While the problem is relatively easy to understand - take a container, copy elements that match a predicate, and return a new container - it's good to exercise with the C++ Standard Library and check a few ideas. We can also apply some Modern C++ techniques, including C++23. Let's start! The article was written in 2021 and recently updated in late 2025 to include additional techniques from C++23. Additionally, the text is also republished on the ACCU website: ACCU Overload, 33: 15 Different Ways to Filter Containers in Modern C++. The Problem Statement To be precise, by a filter I mean a function with the following interface: auto Filter(const Container& cont, UnaryPredicate p) {} It takes a container and a predicate, and creates an output container with elements (copies) that satisfy the predicate. We can use it like the following: const std::vector<std::string> vec{ "Hello", "**txt", "World", "error", "warning", "C++", "****" }; auto filtered = Filter(vec, [](auto& elem) { return !elem.starts_with('*'); }); // filtered should have "Hello", "World", "error", "warning", "C++" Writing such a function can be a good exercise with various options and algorithms in the Standard Library. What's more, our function hides internal mechanisms like iterators, so it's more like a range-based version. Let's start with the first option: Good old Raw Loops While it's good to avoid raw loops, they might help us to fully understand the problem. For our filtering problem, we can write the following code: // filter v1 template <typename T, typename Pred> auto FilterRaw(const std::vector<T>& vec, Pred p) { std::vector<T> out; for (auto&& elem : vec) if (p(elem)) out.push_back(elem); return out; } Simple yet very effective. Please note some nice features of this straightforward implementation. The code uses auto return type deduction, so there's no need to write the explicit type (although it could be just std::vector<

## Understanding std::shared\_mutex from C++17

DevFeed: [Understanding std::shared\_mutex from C++17](<https://devfeed.tech/articles/understanding-std-shared-mutex-from-c-17-53320.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2026/shared_mutex/>)

Published: 2026-02-14T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [locking](<https://devfeed.tech/topics/locking.md>), [Code](<https://devfeed.tech/topics/code.md>), [Scalability](<https://devfeed.tech/topics/scalability.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [code](<https://devfeed.tech/tags/code.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [mutex](<https://devfeed.tech/tags/mutex.md>), [parallelism](<https://devfeed.tech/tags/parallelism.md>), [scalability](<https://devfeed.tech/tags/scalability.md>)

### AI overview

A practical C++ tutorial explaining how std::shared_mutex differs from std::mutex. It uses a thread-safe counter to show how shared ownership allows multiple concurrent readers while exclusive ownership protects writes, improving scalability for read-mostly data.

### Source excerpt

In this article, we'll start with a basic example using std::mutex, look at its limitations, and then introduce std::shared_mutex, a reader-writer mutex added in C++17. Even in 2026, with many new concurrency features available, std::shared_mutex is still a valuable and practical tool. Let's jump in. A Simple Thread-Safe Counter with std::mutex We'll begin with a small example (a standard "hello world" for this type of mutexes): a counter object that multiple threads can access: #include <mutex> class Counter { public: int get() const { std::lock_guard<std::mutex> lock(mutex_); return value_; } void increment() { std::lock_guard<std::mutex> lock(mutex_); ++value_; } private: mutable std::mutex mutex_; int value_{0}; }; Nothing scary so far, and this implementation is correct, thread-safe, and easy to understand. However, there's a significant limitation: All access is exclusive. Only one thread can call get() or increment() at any given time, even though get() does not modify the state. When std::mutex Becomes a Bottleneck In many real-world programs, shared data is read frequently and might be rarely updated/overriden. For example: configuration data caches lookup tables statistics and metrics With std::mutex, even multiple read-only operations block each other. This limits scalability and wastes available parallelism. Have a look at the following example: int main() { Counter counter; std::vector<std::jthread> threads; threads.emplace_back([&counter] { for (int i = 0; i < 10; ++i) { counter.increment(); std::this_thread::sleep_for(15ms); } }); for (int i = 0; i < 4; ++i) { threads.emplace_back([&counter, i] { for (int j = 0; j < 10; ++j) { std::println("reader {} sees {}", i, counter.get()); std::this_thread::sleep_for(10ms); } }); } } On Compiler Explorer - see here https://godbolt.org/z/cdjrj8hGd - I'm getting the following output: Program returned: 0 reader 0 sees 0 reader 1 sees 1 reader 2 sees 1 reader 3 sees 1 reader 0 sees 1 reader 1 sees 1 reader 2 sees 1

## IIFE for Complex Initialization

DevFeed: [IIFE for Complex Initialization](<https://devfeed.tech/articles/iife-for-complex-initialization-53296.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2016/11/iife-for-complex-initialization/>)

Published: 2026-01-24T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Code](<https://devfeed.tech/topics/code.md>), [function](<https://devfeed.tech/topics/function.md>), [Variable](<https://devfeed.tech/topics/variable.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code](<https://devfeed.tech/tags/code.md>), [function](<https://devfeed.tech/tags/function.md>), [variable](<https://devfeed.tech/tags/variable.md>)

### AI overview

A C++ technique for initializing variables with complex multi-line logic while preserving const qualification. The article explains immediately invoked lambda expressions, also called IIFEs or IILEs, and shows how they can compute a value within the current scope.

### Source excerpt

What do you do when the code for a variable initialization is complicated? Do you move it to another method or write inside the current scope? In this blog post, I'd like to present a trick that allows computing a value for a variable, even a const variable, with a compact notation. Updated in Jan 2026: improved code, added C++26 section, added [&] section, updated code samples and added links to Compiler Explorer. Intro I hope you're initializing most variables as const (so that the code is more explicit, and also compiler can reason better about the code and optimize). For example, it's easy to write: const int myParam = inputParam * 10 + 5; or even: const int myParam = bCondition ? inputParam*2 : inputParam + 10; But what about complex expressions? When we have to use several lines of code, or when the ? operator is not sufficient. 'It's easy' you say: you can wrap that initialization into a separate function. While that's the right answer in most cases, I've noticed that in reality a lot of people write code in the current scope. That forces you to stop using const and code is a bit uglier. You might see something like this: int myVariable = 0; // this should be const... if (bFirstCondition) myVariable = bSecondCondition ? computeFunc(inputParam) : 0; else myVariable = inputParam * 2; // more code of the current function... // and we assume 'myVariable` is const now The code above computes myVariable which should be const. But since we cannot initialize it in one line, then the const modifier is dropped. I highly suggest wrapping such code into a separate method, but recently I've come across a new option. I've got the idea from a great talk by Jason Turner about "Practical Performance Practices" where among various tips I've noticed "IIFE". The IIFE acronym stands for "Immediately-invoked function expression". Thanks to lambda expression, it's now available in C++. We can use it for complex initialization of variables. Extra: You might also encounter: IILE, whi

## 7 Practical std::chrono Calendar Examples (C++20)

DevFeed: [7 Practical std::chrono Calendar Examples (C++20)](<https://devfeed.tech/articles/7-practical-std-chrono-calendar-examples-c-20-53307.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/chrono-calendar-examples/>)

Published: 2025-12-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Computing](<https://devfeed.tech/topics/computing.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [examples](<https://devfeed.tech/tags/examples.md>), [practical](<https://devfeed.tech/tags/practical.md>)

### AI overview

A practical C++20 tutorial demonstrating std::chrono calendar operations, including calculating day-of-year values, finding nth weekdays and month-end dates, iterating over dates, and handling month arithmetic and overflow.

### Source excerpt

This article collects small, self-contained, and practical examples for working with std::chrono calendar types. The previous blog post - see Exploring C++20 std::chrono - Calendar Types - C++ Stories - focused on the building blocks: calendar types, operators, and arithmetic rules. In this post, we'll focus on practical examples like: What's the last business day of the month? When is the third Friday in June? How many days since the start of the year? What happens when I add a month to January 31? And a few more Let's start. 1. Which day of the year is that? Let's begin with a simple example of counting how many days a specific date is from the start of the year. In the previous article, we covered basic arithmetic, so now we can apply that knowledge to calculate the difference between a given date and the beginning of the year. See below: #include <chrono> #include <print> using namespace std::chrono; constexpr std::string_view ordinal_suffix(const days& d) { const auto n = d.count(); const auto last_two = n % 100; if (last_two >= 11 && last_two <= 13) return "th"; switch (n % 10) { case 1: return "st"; case 2: return "nd"; case 3: return "rd"; default: return "th"; } } void print_day_of_year(year_month_day ymd) { const sys_days start_of_year{ ymd.year() / January / 1 }; const sys_days current{ ymd }; const days day_index = (current - start_of_year) + days{1}; std::print("{} is the {}{} day of the year\n", ymd, day_index.count(), ordinal_suffix(day_index)); } int main() { print_day_of_year(2025y / January / 2); print_day_of_year(2025y / November / 11); } Run here @Compiler Explorer A few small details worth noticing: The arithmetic is done entirely in sys_days. The result is one-based (January 1 is day 1), which is usually what people expect. Leap years fall out naturally from the sys_days conversion. 2. Nth weekday of a month If you want to check the date of the third Friday in a given month: #include <chrono> #include <print> int main() { using namespace std::c

## Exploring C++20 std::chrono - Calendar Types

DevFeed: [Exploring C++20 std::chrono - Calendar Types](<https://devfeed.tech/articles/exploring-c-20-std-chrono-calendar-types-53308.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/chrono-calendar-types/>)

Published: 2025-12-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Library](<https://devfeed.tech/topics/library.md>), [standard](<https://devfeed.tech/topics/standard.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [library](<https://devfeed.tech/tags/library.md>), [manipulation](<https://devfeed.tech/tags/manipulation.md>), [review](<https://devfeed.tech/tags/review.md>), [standard](<https://devfeed.tech/tags/standard.md>), [time](<https://devfeed.tech/tags/time.md>)

### AI overview

A review of C++20 calendar support in std::chrono, covering strongly typed calendar types, date construction, literals, operators, and explicit date validation.

### Source excerpt

Before C++20, <chrono> gave us a solid foundation for working with clocks, durations, and time points - but it didn't really know anything about the civil calendar. If you needed to represent "March 15", check whether a date is valid, compute "the third Monday of November", or add a few months to a date, you had to rely on custom utilities, std::tm, or external libraries like Howard Hinnant's excellent date. C++20 finally fills this gap by standardising a complete set of calendar types: year, month, day, weekday, year_month_day, month_day_last, and many more. These types let you express dates in a clear, strongly typed way, without fragile integer arithmetic or manual conversions. All of this comes with a very clean API: more than 40 overloads of the / operator let you build date types fluently, almost like writing calendar expressions. In short, C++20 turns most everyday date manipulation tasks into expressive, readable, and fully standard C++. So let's review the core types and operations. Introduction to Calendar Types In C++20, the library extended durations types to cover days, months, and years: using hours = duration<int, ratio<3600>>; // new in C++20 using days = duration<int, ratio_multiply<ratio<24>, hours::period>>; using weeks = duration<int, ratio_multiply<ratio<7>, days::period>>; using years = duration<int, ratio_multiply<ratio<146097, 400>, days::period>>; using months = duration<int, ratio_divide<years::period, ratio<12>>>; And in C++20, we have the following new calendrical types: name description last_(spec) The type is used in conjunction with other calendar types to specify the last in a sequence. For example, depending on the context, it can represent the last day of a month, or the last day of the week of a month. See examples below... day represents a day of a month. It normally holds values in the range 1 to 31, but may hold non-negative values outside this range. month represents a month of a year. It normally holds values in the range 1 to 1

## C++ Templates: How to Iterate through std::tuple: C++26 Packs and Expansion Statements

DevFeed: [C++ Templates: How to Iterate through std::tuple: C++26 Packs and Expansion Statements](<https://devfeed.tech/articles/c-templates-how-to-iterate-through-std-tuple-c-26-packs-and-expansion-statements-53317.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/tuple-iteration-cpp26/>)

Published: 2025-10-12T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [iteration](<https://devfeed.tech/topics/iteration.md>), [syntax](<https://devfeed.tech/topics/syntax.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [templates](<https://devfeed.tech/tags/templates.md>)

### AI overview

A tutorial on C++26 techniques for iterating over and transforming tuples. It explains structured binding packs and expansion statements, showing how they replace older index_sequence and std::apply approaches with simpler compile-time code.

### Source excerpt

In part 1 of this mini-series, we looked at the basics of iterating over a std::tuple using index_sequence and fold expressions. In part 2, we simplified things with std::apply and even created helpers like for_each_tuple and transform_tuple. So far, we used C++ features up to C++20/23... but now, in C++26, we finally get language-level tools that make tuple iteration straightforward and expressive. In this article, we'll explore two new techniques: Structured bindings can introduce a pack - P1061 - turn a tuple into a pack of variables. Expansion statements P1306 - the ultimate "compile-time loop" syntax. Structured binding packs Structured bindings have been around since C++17, but in C++26 they gained the ability to introduce packs. That means you can bind an arbitrary number of elements without spelling each out. For example: auto [head, ...rest] = std::tuple{1, 2, 3, 4}; // head == 1, rest... expands to (2, 3, 4) This feature gives us a way to expand tuples into parameter packs, and once we have a pack, we can use fold expressions and other familiar template techniques. Printing a tuple We can bind all elements of a tuple into a pack and then fold over it: #include <tuple> #include <iostream> #include <utility> template <typename Tuple> void print_tuple(const Tuple& t) { const auto& [...xs] = t; bool first = true; std::cout << "("; ((std::cout << (std::exchange(first, false) ? "" : ", ") << xs), ...); std::cout << ")"; } int main() { print_tuple(std::make_tuple(1, 2.2, "hello")); } See at Compiler Explorer This is a direct replacement for our old index_sequence or std::apply approaches - now written in plain C++26. (Of course, you can easily update it to work with std::print) Transforming a tuple We can also apply a transformation and create a new tuple: template <typename Tuple, typename Fn> auto transform_tuple(const Tuple& t, Fn&& fn) { const auto& [...xs] = t; return std::make_tuple(fn(xs)...); } std::tuple tp{1, 2, 3}; auto doubled = transform_tuple(tp, [](a

## C++ Templates: How to Iterate through std::tuple: std::apply and More

DevFeed: [C++ Templates: How to Iterate through std::tuple: std::apply and More](<https://devfeed.tech/articles/c-templates-how-to-iterate-through-std-tuple-std-apply-and-more-53299.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2022/tuple-iteration-apply/>)

Published: 2025-09-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [iteration](<https://devfeed.tech/tags/iteration.md>)

### AI overview

This tutorial explores techniques for iterating over C++ tuples using std::apply, including callable objects, variadic function templates, template argument deduction, and compiler behavior. It is the second part of a series and discusses approaches that support more generic tuple processing.

### Source excerpt

In the previous article on the tuple iteration, we covered the basics. As a result, we implemented a function template that took a tuple and could nicely print it to the output. There was also a version with operator <<. Today we can go further and see some other techniques. The first one is with std::apply from C++17, a helper function for tuples. Today's article will also cover some strategies to make the iteration more generic and handle custom callable objects, not just printing. This is the second part of the small series. See the first article here where we discuss the basics. And see the third part about the ultimate solution with C++26. Updated in Sept 2025: Extended the "Return value" section. std:apply approach A handy helper for std::tuple is the std::apply function template that came in C++17. It takes a tuple and a callable object and then invokes this callable with parameters fetched from the tuple. Here's an example: #include <iostream> #include <tuple> int sum(int a, int b, int c) { return a + b + c; } void print(std::string_view a, std::string_view b) { std::cout << "(" << a << ", " << b << ")\n"; } int main() { std::tuple numbers {1, 2, 3}; std::cout << std::apply(sum, numbers) << '\n'; std::tuple strs {"Hello", "World"}; std::apply(print, strs); } Play @Compiler Explorer As you can see, std::apply takes sum or print functions and then "expands" tuples and calls those functions with appropriate arguments. Here's a diagram showing how it works: Ok, but how does it relate to our problem? The critical thing is that std::apply hides all index generation and calls to std::get<>. That's why we can replace our printing function with std::apply and then don't use index_sequence. The first approach - working? The first approach that came to my mind was the following - create a variadic function template that takes Args... and pass it to std::apply: template <typename... Args> void printImpl(const Args&... tupleArgs) { size_t index = 0; auto printElem = [&in

## Structured bindings in C++17, 8 years later

DevFeed: [Structured bindings in C++17, 8 years later](<https://devfeed.tech/articles/structured-bindings-in-c-17-8-years-later-53315.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/structured-bindings-cpp26-updates/>)

Published: 2025-08-31T00:00:00Z

Content type: article

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [Code](<https://devfeed.tech/topics/code.md>), [iteration](<https://devfeed.tech/topics/iteration.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [syntax](<https://devfeed.tech/topics/syntax.md>), [object](<https://devfeed.tech/topics/object.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code](<https://devfeed.tech/tags/code.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [iteration](<https://devfeed.tech/tags/iteration.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

An article explaining C++ structured bindings, including their use with maps, the underlying syntax, compiler behavior, and examples from real code. It also discusses additions planned for C++26.

### Source excerpt

Structured binding is a C++17 feature that allows you to bind multiple variables to the elements of a structured object, such as a tuple or struct. This can make your code more concise and easier to read, especially when working with complex data structures. On this blog, we already covered this functionality, but we'll talk about some good C++26 additions and real code use cases. Iterating through maps An excellent demonstration of structured bindings is an iteration through a map object. If you have a std::map of elements, you might know that internally, they are stored as pairs of <const Key, ValueType>. Now, when you iterate through elements, you can do: for (const auto& elem : myMap) { ... } You need to write elem.first and elem.second to refer to the key and the value. std::map<KeyType, ValueType> myMap = getMap(); // C++14: for (const auto& elem : myMap) { // elem.first - is the key // elem.second - is the value } One of the coolest use cases of structured binding is that we can use it inside a range-based for loop: // C++17: for (const auto& [key,val] : myMap) { // use key/value directly } In the above example, we bind to a pair of [key, val] so we can use those names in the loop. Before C++17, you had to operate on an iterator from the map - which returns a pair <first, second>. Using the real names key/value is more expressive. The above technique can be used in the following example: #include <map> #include <iostream> int main() { const std::map<std::string, int> mapCityPopulation { { "Beijing", 21'707'000 }, { "London", 8'787'892 }, { "New York", 8'622'698 } }; for (const auto&[city, population] : mapCityPopulation) std::cout << city << ": " << population << '\n'; } Run @Compiler Explorer In the loop body, you can safely use the city and population variables. The Syntax The basic syntax for structured bindings is as follows: auto [a, b, c, ...] = expression; auto [a, b, c, ...] { expression }; auto [a, b, c, ...] ( expression ); The compiler introduces a

## How to Avoid Thread-Safety Cost for Functions' static Variables

DevFeed: [How to Avoid Thread-Safety Cost for Functions' static Variables](<https://devfeed.tech/articles/how-to-avoid-thread-safety-cost-for-functions-static-variables-53316.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/thread_safety_function_statics/>)

Published: 2025-08-23T00:00:00Z

Content type: article

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [functions](<https://devfeed.tech/tags/functions.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threads](<https://devfeed.tech/tags/threads.md>)

### AI overview

This C++ article explains function-scope static variables, including lazy initialization and the thread-safe initialization guarantee introduced in C++11. It also examines compiler-specific behavior and benchmark results comparing local and global statics.

### Source excerpt

In this blog post, we'll look at static variables defined in a function scope. We'll see how they are implemented and how to use them. What's more, we'll discuss several cases where we can avoid extra thread-safety cost. Let's start. Introduction As you may know, C++ offers a way to define static variables in a function/block scope: void foo() { static int counter = 0; ++counter; } Above, the counter variable will be initialized and created when foo() is invoked for the first time. In other words, a static local variable is initialized lazily. The counter is kept "outside" the function's stack space. This allows, for example, to keep the state, but limit the visibility of the global object. Here's the full example: #include <iostream> int foo() { static int counter = 0; return ++counter; } int main() { foo(); foo(); foo(); auto finalCounter = foo(); std::cout << finalCounter; } Run @Compiler Explorer If you run the program, you'll get 4 as the output. Static local variables, since C++11, are guaranteed to be initialized in a thread-safe way. The object will be initialized only once if multiple threads enter a function with such a variable. Have a look below: #include <iostream> #include <thread> struct Value { Value(int x) : v(x) { std::cout << "Value(" << v << ")\n"; } ~Value() noexcept { std::cout << "~Value(" << v << ")\n"; } int v { 0 }; }; void foo() { static Value x { 10 }; } int main() { std::jthread worker1 { foo }; std::jthread worker2 { foo }; std::jthread worker3 { foo }; } Run @Compiler Explorer The example creates three threads that call the foo() simple function. However, on GCC, you can also try compiling with the following flags: -std=c++20 -lpthread -fno-threadsafe-statics And then the output might be as follows: Value(Value(1010) ) Value(10) ~Value(10) ~Value(10) ~Value(10) Three static objects are created now! On Windows, MSVC, you can play with /Zc:threadSafeInit and disable this behaviour. See /Zc:threadSafeInit (Thread-safe Local Static Initial

## How to Split Ranges in C++23

DevFeed: [How to Split Ranges in C++23](<https://devfeed.tech/articles/how-to-split-ranges-in-c-23-53314.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/ranges_split_chunk/>)

Published: 2025-05-16T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [how-to](<https://devfeed.tech/tags/how-to.md>)

### AI overview

A practical tutorial on splitting and grouping ranges in C++ using the C++20 views::split and views::lazy_split adaptors, plus the C++23 views::chunk and views::chunk_by adaptors. It explains range requirements and demonstrates text, generic-range, stream, fixed-size batch, packet, parity, and sentence-processing examples.

### Source excerpt

In this blog post, we'll continue looking at ranges and this time explore ways to split them into sub-ranges. So we'll take a look at views::split, views::chunk, and views::chunk_by. We'll walk through two examples for each adaptor: one simple and one slightly more advanced, to highlight their practical uses. Let's go. Splitting Ranges with views::split, C++20 If you want to split a range using some "delimeter," then views::split (or ranges::split_view) will do the job. template< ranges::forward_range V, ranges::forward_range Pattern > // .. requires... class split_vie : public ranges::view_interface<split_view<V, Pattern>> Both of the ranges V and Pattern have to be forward_range. Notice that you need to use a pattern; it cannot be a condition. Example 1: Splitting a Sentence into Words #include <print> #include <ranges> #include <string_view> int main() { using namespace std::string_view_literals; constexpr auto text = "C++ is powerful and elegant"sv; for (auto part : std::views::split(text, ' ')) std::print("'{}' ", std::string_view(part)); } Play @Compiler Explorer The output: 'C++' 'is' 'powerful' 'and' 'elegant' A classic example that splits a sentence into words. We convert each subrange to std::string_view for easy printing. We can also extend this and use not just one character: constexpr auto text = "C++breakisbreakpowerfulbreakandbreakelegant"sv; for (auto part : std::views::split(text, "break"sv)) std::print("'{}' ", std::string_view(part)); Example 2: Splitting Not Just Text split can be applied to any forward range, so not just text: #include <print> #include <ranges> #include <vector> #include <utility> int main() { using Point = std::pair<int, int>; std::vector<Point> path = { {0, 0}, {1, 1}, {-1, -1}, // marker: {-1, -1} {2, 2}, {3, 3}, {-1, -1}, {4, 4}, {5, 5} }; for (auto segment : std::views::split(path, Point{-1, -1})) std::print("Segment: {}\n", segment); } See @Compiler Explorer And the output: Segment: [(0, 0), (1, 1)] Segment: [(2, 2), (3, 3

## Views as Data Members for Custom Iterators

DevFeed: [Views as Data Members for Custom Iterators](<https://devfeed.tech/articles/views-as-data-members-for-custom-iterators-53312.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/custom_iter_cpp_20_ranges_views/>)

Published: 2025-04-22T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Code](<https://devfeed.tech/topics/code.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [clang](<https://devfeed.tech/topics/clang.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [exception](<https://devfeed.tech/tags/exception.md>)

### AI overview

This tutorial implements a two-dimensional iterator for a vector of vectors in C++. It compares a manual approach that tracks inner and outer positions with a C++20 ranges and views approach for flattening nested ranges.

### Source excerpt

In this blog post, we'll write an iterator that works with a vector of vectors. We'll explore a "manual" version as well as leverage C++20 ranges/views to do the hard work. The problem statement What's the use case? See this popular interview question (found in DailyCodingProblem: https://www.dailycodingproblem.com/) Implement a 2D iterator class. It will be initialized with an array of arrays and should implement the following methods: next() : returns the next element in the array of arrays. If there are no more elements, raise an exception. has_next() : returns whether or not the iterator still has elements left. For example, given the input [[1, 2], [3], [], [4, 5, 6]] , calling next() repeatedly should output 1, 2, 3, 4, 5, 6 . Transforming the problem into C++, we can write the following client code: int main() { std::vector<std::vector<int>> input = {{1, 2}, {3}, {}, {4, 5, 6}}; TwoDIterator it(input); while (it.has_next()) std::print("{} ", it.next()); } The case is to implement TwoDIterator. Initial Version The main idea for the iterator is to track the "inner" position as well as the "outer". When the inner position reaches the end of some inner vector, we need to check if we have more vectors to traverse. Here's some basic code: #include <vector> #include <stdexcept> #include <print> class TwoDIterator { public: using Vec2D = std::vector<std::vector<int>>; TwoDIterator(const Vec2D& data) : data_(data), outer_(0), inner_(0) { advance_to_next_valid(); } bool has_next() const { return outer_ < data_.size(); } int next() { if (!has_next()) throw std::out_of_range("No more elements"); int val = data_[outer_][inner_]; ++inner_; advance_to_next_valid(); return val; } private: void advance_to_next_valid() { while (outer_ < data_.size() && inner_ >= data_[outer_].size()) { ++outer_; inner_ = 0; } } const Vec2D& data_; size_t outer_, inner_; }; int main() { std::vector<std::vector<int>> input = {{1, 2}, {3}, {}, {4, 5, 6}}; TwoDIterator it(input); while (it.has_nex

## Details of std::mdspan from C++23

DevFeed: [Details of std::mdspan from C++23](<https://devfeed.tech/articles/details-of-std-mdspan-from-c-23-53309.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/cpp23_mdspan/>)

Published: 2025-02-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [layout](<https://devfeed.tech/topics/layout.md>), [data](<https://devfeed.tech/topics/data.md>), [object](<https://devfeed.tech/topics/object.md>), [constructor](<https://devfeed.tech/topics/constructor.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [data](<https://devfeed.tech/tags/data.md>), [details](<https://devfeed.tech/tags/details.md>), [layout](<https://devfeed.tech/tags/layout.md>)

### AI overview

This tutorial explains C++23's std::mdspan, a multidimensional data view. It covers its declaration, static and dynamic extents, construction options, object size, and layout policies, with notes on related C++26 additions.

### Source excerpt

In this article, we'll see details of std::mdspan, a new view type tailored to multidimensional data. We'll go through type declaration, creation techniques, and options to customize the internal functionality. Type declaration The type is declared in the following way: template< class T, class Extents, class LayoutPolicy = std::layout_right, class AccessorPolicy = std::default_accessor<T> > class mdspan; And it has its own header <mdspan>. The main proposal for this feature can be found at https://wg21.link/P0009 Following the pattern from std::span, we have a few options to create mdspan: with dynamic or static extent. The key difference is that rather than just one dimension, we can specify multiple. The declaration also gives more options in the form of LayoutPolicy and AccessorPolicy. More on that later. Static Extent std::vector<int> vec = {1, 2, 3, 2, 4, 5, 3, 5, 6, 7, 8, 9}; std::mdspan<int, std::extents<size_t, 3, 3>> mat3x3 { vec.data() }; std::print("sizeof: {}, rank: {}, ext 0: {}, ext 1: {}\n", sizeof(mat3x3), mat3x3.rank(), mat3x3.extent(0), mat3x3.extent(1)); The output: sizeof: 8, rank: 2, ext 0: 3, ext 1: 3 Run @Compiler Explorer Dynamic Extent And the dynamic option: std::mdspan<int, std::dextents<size_t, 2>> mat2x2 { vec.data(), 2, 2 }; std::print("sizeof: {}, rank: {}, ext 0: {}, ext 1: {}\n", sizeof(mat2x2), mat2x2.rank(), mat2x2.extent(0), mat2x2.extent(1)); The output: sizeof: 24, rank: 2, ext 0: 2, ext 1: 2 Run @Compiler Explorer The line: std::mdspan<int, std::dextents<size_t, 2>> Is equivalent: std::mdspan<int, std::extents<size_t, std::dynamic_extents, std::dynamic_extents>> In other words, dextents stands for dynamic extents. And as of C++26, we can also simplify it with std::dims: std::mdspan<int, std::dims<2>> mat2x2 { vec.data(), 2, 2 }; Sizeof mdspan As you can see, similarly to std::span, when the size is known at compile time, the object can be smaller (it doesn't have to store the dynamic size). Run here: @Compiler Explorer Constru

## Adjacency Matrix and std::mdspan, C++23

DevFeed: [Adjacency Matrix and std::mdspan, C++23](<https://devfeed.tech/articles/adjacency-matrix-and-std-mdspan-c-23-53310.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/cpp23_mdspan_adj/>)

Published: 2025-02-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [Graphs](<https://devfeed.tech/topics/graphs.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Code](<https://devfeed.tech/topics/code.md>), [Matrix](<https://devfeed.tech/topics/matrix-org.md>), [Mathematics](<https://devfeed.tech/topics/mathematics.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [return](<https://devfeed.tech/topics/return.md>)

Tags: [adjacency-matrix](<https://devfeed.tech/tags/adjacency-matrix.md>), [array](<https://devfeed.tech/tags/array.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [efficiency](<https://devfeed.tech/tags/efficiency.md>), [fragmentation](<https://devfeed.tech/tags/fragmentation.md>), [graph](<https://devfeed.tech/tags/graph.md>), [graph-theory](<https://devfeed.tech/tags/graph-theory.md>), [graphs](<https://devfeed.tech/tags/graphs.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [locality](<https://devfeed.tech/tags/locality.md>), [matrix](<https://devfeed.tech/tags/matrix.md>), [overhead](<https://devfeed.tech/tags/overhead.md>), [vector](<https://devfeed.tech/tags/vector.md>)

### AI overview

A tutorial on implementing adjacency matrices for undirected weighted graphs in C++23. It compares nested vectors with a contiguous vector and then introduces std::mdspan as a non-owning multidimensional view to simplify indexing and improve memory locality.

### Source excerpt

In graph theory, an adjacency matrix is a square matrix used to represent a finite (and usually dense) graph. The elements of the matrix indicate whether pairs of vertices are adjacent or not, and in weighted graphs, they store the edge weights. In many beginner-level tutorials, adjacency matrices are implemented using vector of vectors (nested dynamic arrays), but this approach has inefficiencies due to multiple memory allocations. C++23 introduces std::mdspan, which provides a more efficient way to handle multidimensional data structures without the overhead of nested containers. In this blog post, we'll explore various implementations of an adjacency matrix, starting with a basic approach and progressively improving it using std::mdspan. Starting slow Let's start with a straightforward implementation using a vector of vectors to represent the adjacency matrix. #include <iostream> #include <vector> #include <limits> #include <print> template <typename T> class Graph { public: static constexpr T INF = std::numeric_limits<T>::max(); private: std::vector<std::vector<T>> adjacencyMatrix; size_t numVertices; public: Graph(size_t vertices) : numVertices(vertices) , adjacencyMatrix(vertices, std::vector<T>(vertices, INF)) { for (size_t i = 0; i < numVertices; i++) adjacencyMatrix[i][i] = 0; } void addEdge(size_t u, size_t v, T weight) { if (u < numVertices && v < numVertices && u != v) { adjacencyMatrix[u][v] = weight; adjacencyMatrix[v][u] = weight; } } bool isConnected(size_t u, size_t v) const { return (u < numVertices && v < numVertices && adjacencyMatrix[u][v] != INF); } const std::vector<std::vector<T>>& getAdjacencyMatrix() const { return adjacencyMatrix; } }; template <typename T> void printGraph(const Graph<T>& g) { std::print("Adjacency Matrix:\n"); for (const auto& row : g.getAdjacencyMatrix()) { for (T weight : row) { if (weight == Graph<T>::INF) std::print(" ∞ "); else std::print(" {:3} ", weight); } std::println(); } } The class represents an undirected wei

## How to use std::span from C++20

DevFeed: [How to use std::span from C++20](<https://devfeed.tech/articles/how-to-use-std-span-from-c-20-53301.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2023/span-cpp20/>)

Published: 2025-02-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Code](<https://devfeed.tech/topics/code.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [how-to](<https://devfeed.tech/tags/how-to.md>)

### AI overview

This tutorial explains how to use C++20's std::span, a lightweight non-owning view over contiguous data. It covers static and dynamic extents, construction options, passing spans to functions, and the benefits of avoiding separate pointer-and-size parameters.

### Source excerpt

In this article, we'll look at std::span, which has been available since C++20. This "view" type is more generic than string_view and can help work with arbitrary contiguous collections. Updated in Feb 2025: added section about returning spans and C++26 improvements (.at() and creatoion from initializer list). A Motivating Example Here's an example that illustrates the primary use case for std::span: In traditional C (or low-level C++), you'd pass an array to a function using a pointer and a size like this: void process_array(int* arr, std::size_t size) { for(std::size_t i = 0; i < size; ++i) { // do something with arr[i] } } std::span simplifies the above code: void process_array(std::span<int> arr_span) { for(auto& elem : arr_span) { // do something with elem } } The need to pass a separate size variable is eliminated, making your code less error-prone and more expressive. And in essence: std::span<T> is: a lightweight abstraction of a contiguous sequence of values of type T, more or less implemented as struct { T * ptr; std::size_t length; }, a non-owning type (i.e. a "reference type" rather than a "value type"). Construction of std::span std::span lives in its own new header <span>. It's defined as follows: template<class T, std::size_t Extent = std::dynamic_extent> class span; To create this object, you have two basic options: static extent and dynamic: Static Extent When you know the size at compile-time: int arr[] = {1, 2, 3, 4, 5}; std::span<int, 5> arr_span {arr}; //std::span<int, 2> arr_span2 {arr}; // error size doesn't match Run @Compiler Explorer Here, the 5 is an integral part of the type. You'll get a compiler error if you try to initialize this span with an array of different sizes. Dynamic Extent When you only know the size at runtime, like when working with vectors: int arr[] = {1, 2, 3, 4, 5}; std::vector v { 1, 2, 3, 4, 5}; std::span<int> arr_span {arr}; // dynamic extent std::span<int> vec_span {v}; // also! See @Compiler Explorer Notice the abs

## Improving Code Safety in C++26: Managers and Dangling References

DevFeed: [Improving Code Safety in C++26: Managers and Dangling References](<https://devfeed.tech/articles/improving-code-safety-in-c-26-managers-and-dangling-references-53311.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/cpp26-safety-temp/>)

Published: 2025-01-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [bug](<https://devfeed.tech/topics/bug.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [diagnostics](<https://devfeed.tech/tags/diagnostics.md>), [error](<https://devfeed.tech/tags/error.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [static](<https://devfeed.tech/tags/static.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

A tutorial on improving a C++ configuration manager by fixing a dangling reference to a temporary object, using C++26 diagnostics to catch the error, and avoiding stack-overflow risks from large default configuration objects.

### Source excerpt

In this blog post, we'll explore ways to improve the safety of a simple configuration manager. We'll handle common pitfalls like dangling references and excessive stack usage. Additionally, we'll see how C++26 helps enforce safer coding practices with stricter diagnostics and improved handling of large objects. Let's go. Step 1: The Buggy Implementation Below is a simple example of a manager object that stores various configs in a map and provides a method to retrieve them. When a requested configuration isn't found, the code attempts to return a default certificate: #include <map> #include <string> #include <iostream> #include <vector> #include <cstdint> class ConfigManager { private: std::map<std::string, std::vector<uint8_t>> configs; public: ConfigManager() { configs["database"] = { 'h','o','s','t','=','l','o','c','a','l','h','o','s','t',';', 'p','o','r','t','=','5','4','3','2' }; } const std::vector<uint8_t>& findConfig(const std::string& name) const { auto it = configs.find(name); if (it != configs.end()) return it->second; return {42}; } }; int main() { ConfigManager configManager; const std::vector<uint8_t>& dbConfig = configManager.findConfig("database"); std::cout << "Database config: "; for (uint8_t byte : dbConfig) { std::cout << static_cast<char>(byte); } } See @Compiler Explorer Do you see a potential error in this code? . . . At first glance, the code looks harmless. However, if the requested entry isn't found, the function returns a reference to a temporary std::vector. Once the function exits, that temporary is destroyed--leaving you with a dangling reference and undefined behavior. Compiler Warnings Ok, the bug was easy... and compilers have warned about this case for a long time. While this is helpful, it's still possible to overlook or disable the warning, especially if your project is large. So let's try enabling C++26 mode... for example on GCC 14 you'll get: error: returning reference to temporary [-Wreturn-local-addr] Great! Now, we cannot skip th

## 8 More C++23 Examples

DevFeed: [8 More C++23 Examples](<https://devfeed.tech/articles/8-more-c-23-examples-53305.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2024/cpp23_more_examples/>)

Published: 2024-12-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [formatting](<https://devfeed.tech/topics/formatting.md>), [function](<https://devfeed.tech/topics/function.md>), [input](<https://devfeed.tech/topics/input.md>), [file](<https://devfeed.tech/topics/file.md>)

Tags: [examples](<https://devfeed.tech/tags/examples.md>), [file](<https://devfeed.tech/tags/file.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [functions](<https://devfeed.tech/tags/functions.md>), [input](<https://devfeed.tech/tags/input.md>)

### AI overview

A tutorial presents eight larger examples combining C++23 library features, including ranges-to-container conversion, formatted output, monadic operations, lazy file-reading sequences, and multidimensional data processing.

### Source excerpt

In this article, you'll see eight larger examples that illustrate the changes in C++23. C++23 brings a ton of cool features, as you can see in my two previous articles (here and here). So far, we explored each new addition one by one, but I'd like to share more examples that combine multiple features. Here we go: 1. std::ranges::to<> The ranges::to<> feature allows you to convert ranges into containers easily: #include <ranges> #include <vector> #include <iostream> #include <string> #include <unordered_map> #include <map> int main() { std::vector<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::unordered_map<int, std::string> number_to_text = { {1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}, {5, "five"}, {6, "six"}, {7, "seven"}, {8, "eight"}, {9, "nine"}, {10, "ten"} }; auto even_numbers = numbers | std::views::filter([](int n) { return n % 2 == 0; }) | std::ranges::to<std::vector>(); auto text_numbers_map = even_numbers | std::views::transform([&number_to_text](int n) { return std::pair{n, number_to_text.contains(n) ? number_to_text[n] : "unknown" } }) | std::ranges::to<std::map>(); std::cout << "Even numbers: "; for (int n : even_numbers) std::cout << n << " "; std::cout << "\nTextual numbers:\n"; for (const auto& [k, v] : text_numbers_map) std::cout << k << " -> " << v << '\n'; } Run @Compiler Explorer As you can see, there's no issue in creating not only vectors but maps as well. 2. std::print and std::println The new formatted output library simplifies printing. Here's an example that demonstrates alignment, formatting, and table creation: #include <print> #include <unordered_map> #include <string> #include <numeric> int main() { // Store the data in an unordered_map (country -> size in km²) std::unordered_map<std::string, double> country_sizes = { {"USA", 9833517}, {"Canada", 9984670}, {"Australia", 7692024}, {"China", 9596961}, {"Poland", 312696} }; constexpr double KM_TO_MI = 0.386102; // Conversion factor const double total_km = std::accumulate(coun

## C++23 Library Features and Reference Cards

DevFeed: [C++23 Library Features and Reference Cards](<https://devfeed.tech/articles/c-23-library-features-and-reference-cards-53304.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2024/cpp23_lib/>)

Published: 2024-12-08T00:00:00Z

Content type: article

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [standard](<https://devfeed.tech/topics/standard.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>)

Tags: [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [headers](<https://devfeed.tech/tags/headers.md>), [library](<https://devfeed.tech/tags/library.md>), [reference](<https://devfeed.tech/tags/reference.md>), [standard](<https://devfeed.tech/tags/standard.md>)

### AI overview

A reference guide to C++23 standard library features, covering new headers, stacktrace support, scoped-enum utilities, pointer wrappers, container construction, ranges algorithms, and view additions. It includes short explanations and code examples.

### Source excerpt

In this blog post, you'll see all C++23 library features! Each with a short description and additional code example. Prepare for a ride! For language features please see the previous article: C++23 Language Features and Reference Cards - C++ Stories Want your own copy to print? If you like, I prepared PDF I packed both language and the Standard Library features. Each one has a short description and an example if possible. All of the existing subscribers of my mailing list have already got the new document, so If you want to download it just subscribe here: Download a free copy of C++23 Ref Card! Please notice that along with the new ref card you'll also get C++20 and C++17 language reference card that I initially published three years ago. With this "package" you'll quickly learn about all of the latest parts that Modern C++ acquired over the last few years. New Headers expected flat_map, flat_set generator mdspan print spanstream stacktrace stdfloat Stacktrace Library P0881 Based on Boost.Stacktrace allows for more context when debugging code. The library defines components to store the stacktrace of the current thread of execution and query information about the stored stacktrace at runtime. #include <iostream> #include <stacktrace> void foo() { std::cout << std::stacktrace::current(); } int main() { [] { foo(); }(); } Experiment @Compiler Explorer, note that GCC 14 requires to be linked with -lstdc++exp. Possible output on GCC: 0# foo() at /app/example.cpp:5 1# operator() at /app/example.cpp:10 2# main at /app/example.cpp:11 3# at :0 4# __libc_start_main at :0 5# _start at :0 is_scoped_enum & to_underlying P1048R1 (is_scoped_enum), P1682R3 (to_underlying) #include <print> #include <utility> // for std::to_underlying enum class Color: uint8_t { Red = 1, Green = 2, Blue = 3 }; enum Col { Red, Green, Blue }; int main() { Color c = Color::Blue; // Pre-C++23: verbose casting auto old_way = static_cast<std::underlying_type_t<Color>>(c); // C++23: clean and simple auto

## C++23 Language Features and Reference Cards

DevFeed: [C++23 Language Features and Reference Cards](<https://devfeed.tech/articles/c-23-language-features-and-reference-cards-53303.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2024/cpp23_lang/>)

Published: 2024-11-17T00:00:00Z

Content type: article

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [standard](<https://devfeed.tech/topics/standard.md>)

Tags: [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [example](<https://devfeed.tech/tags/example.md>), [language](<https://devfeed.tech/tags/language.md>), [reference](<https://devfeed.tech/tags/reference.md>), [standard](<https://devfeed.tech/tags/standard.md>)

### AI overview

A practical overview of C++23 language features, with short descriptions and code examples. It also outlines the standard's development timeline and highlights major additions finalized through 2023.

### Source excerpt

C++23 Language Features In this blog post, you'll see all C++23 language features! Each with short description and additional code example. Prepare for a ride! For library features please see the next article: C++23 Library Features and Reference Cards - C++ Stories Want your own copy to print? If you like, I prepared PDF I packed both language and the Standard Library features. Each one has a short description and an example if possible. All of the existing subscribers of my mailing list have already got the new document, so If you want to download it just subscribe here: Download a free copy of C++23 Ref Card! Please notice that along with the new ref card you'll also get C++20 and C++17 language reference card that I initially published three years ago. With this "package" you'll quickly learn about all of the latest parts that Modern C++ acquired over the last few years. Timeline Here's a short overview about the timeline for the new standard. February 2020 (Prague): Final C++20 meeting where initial plans for C++23 were adopted Key planned features: library support for coroutines, modular standard library, executors, and networking June 2020: First planned WG21 meeting for C++23 in Varna was cancelled due to COVID-19 pandemic November 2020: New York meeting cancelled, moved to virtual format Key additions: size_t literals, stacktrace library, contains() member functions, C atomic interoperability February 2021: Virtual meeting Notable features: Lambda expression simplifications, variant improvements, conditionally borrowed ranges June 2021: Virtual summer plenary meeting Major additions: if consteval, spanstream, out_ptr/inout_ptr, constexpr improvements October 2021: Virtual autumn plenary meeting Significant features: Explicit this parameter, multidimensional subscript operator, zip ranges February 2022: Virtual meeting Key additions: std::expected, ranges::to, windowing range adaptors July 2022: Virtual meeting Major features: static operator(), UTF-8 source

## Around the World in C++: Exploring Time Zones with std::chrono

DevFeed: [Around the World in C++: Exploring Time Zones with std::chrono](<https://devfeed.tech/articles/around-the-world-in-c-exploring-time-zones-with-std-chrono-53306.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2024/zones_around_world_chrono/>)

Published: 2024-11-10T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Library](<https://devfeed.tech/topics/library.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [database](<https://devfeed.tech/tags/database.md>), [library](<https://devfeed.tech/tags/library.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

A tutorial on using C++20's std::chrono time-zone support to inspect the IANA Time Zone Database and identify unusual offsets and daylight-saving rules. It examines examples including Nepal's UTC+5:45 offset and Lord Howe Island's 30-minute daylight-saving adjustment.

### Source excerpt

While most time zones use simple hour offsets from UTC, some regions have chosen unusual time differences. In this blog post, we'll explore how we can discover such zones using C++20's chrono library. We'll use GCC 14.2 as it fully supports C++20 chrono and also std::print from C++23. First Attempt: Basic Zone Iteration C++20 introduced comprehensive time zone support through the <chrono> library. The implementation relies on the IANA Time Zone Database (also known as the "tz database" or "zoneinfo"), which is the de facto standard for time zone information used by most operating systems and programming languages. The Time Zone Database In C++20, the time zone database is represented by the tzdb class: namespace std::chrono { struct tzdb { string version; // IANA time zone database version vector<time_zone> zones; // Time zone container vector<time_zone_link> links; // Alternative names vector<leap_second> leap_seconds; // Leap second info }; } Essential aspects of the database: It's read-only - users cannot construct or modify a tzdb Access is provided through two global functions: get_tzdb(): Returns the current database get_tzdb_list(): Returns the list of available database versions Here's how to access the database: #include <chrono> #include <print> #include <cassert> int main() { const auto& db = std::chrono::get_tzdb(); std::print("Current DB version: {}\n", db.version); const auto& db_list = std::chrono::get_tzdb_list(); auto size = std::distance(db_list.begin(), db_list.end()); std::print("Available versions: {}\n", size); assert(&db_list.front() == &db); } See at Compiler Explorer The database provides several key components: Zones (db.zones): Primary container of time zone information Each zone contains complete historical and current rules Examples: "America/New_York", "Europe/London" Links (db.links): Alternative names for existing zones Useful for backward compatibility Example: "EST" links to "America/New_York" Leap Seconds (db.leap_seconds): Records

[Next page](<https://devfeed.tech/sources/c-stories.md?cursor=WyIyMDI0LTExLTEwVDAwOjAwOjAwKzAwOjAwIiwgIjRjOWQxZjA5LWY3NzgtNGYzOC1iMGYyLTY5MzQzYWQ5Y2YwNSJd>)