The C++ Stories Weekly Newsletter

Join ~11000 developers who read about Modern C++, news reports, tools, and more! A new email every Monday.
Bonuses included! C++17/C++20 ref cards and more!

The above field is supplemented with consent to receive a newsletter containing information and marketing content about the cppstories.com portal from Bartłomiej Filipek codebf based in Krakow. The consent may be withdrawn at any time. See the full Privacy Policy.


See the latest articles:

Using std::expected from C++23

Updated:

In this article, we’ll go through a new vocabulary type introduced in C++23. std::expected is a type specifically designed to return results from a function, along with the extra error information. Motivation   Imagine you’re expecting a certain result from a function, but oops… things don’t always go as planned:

READ MORE...

Six Handy Operations for String Processing in C++20/23

Updated:

In this article, we’ll explore six practical string processing operations introduced in C++20 and C++23. These features represent an evolution in this crucial area, covering a spectrum of operations from searching and appending to creation and stream handling. Let’s start with a simple yet long-awaited feature… 1. contains(), C++23   Finally, after decades of standardization, we have a super easy way to check if there’s one string inside the other.

READ MORE...

Formatting Custom types with std::format from C++20

Updated:

std::format is a large and powerful addition in C++20 that allows us to format text into strings efficiently. It adds Python-style formatting with safety and ease of use. This article will show you how to implement custom formatters that fit into this new std::format architecture. Updated in Nov 2023: reflect the constness of the format() function, clarified in LWG issue 3636.

READ MORE...

C++20, Spans, Threads and Fun

Updated:

In this post, we’ll have fun using C++20’s spans to process data on multiple threads. What’s more, we’ll be equipped with the latest concurrency features from C++20. This text was motivated by the following comment under my recent article on std::span: But why does this article… not show the major use case?

READ MORE...

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

Updated:

In this article, we’ll look at std::span which is more generic than string_view and can help work with arbitrary contiguous collections. 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:

READ MORE...

How to Use Monadic Operations for `std::optional` in C++23

Updated:

In this post we’ll have a look at new operations added to std::optional in C++23. These operations, inspired by functional programming concepts, offer a more concise and expressive way to work with optional values, reducing boilerplate and improving code readability. Let’s meet and_then(), transform() and or_else(), new member functions. Traditional Approach with if/else and optional C++20   In C++20 when you work with std::optional you have to rely heavily on conditional checks to ensure safe access to the contained values.

READ MORE...

Five Advanced Initialization Techniques in C++: From reserve() to piecewise_construct and More.

Updated:

From dynamic container operations to compile-time constants, C++ offers a variety of techniques (as in this famous Meme :)). In this article, we’ll delve into advanced initialization methods likereserve() and emplace_backfor containers to tuples with piecewise_construct and forward_as_tuple. Thanks to those techniques, we can reduce the number of temporary objects and create variables more efficiently.

READ MORE...