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:

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...

Finite State Machine with std::variant

Updated:

In this blog post, I’ll show you how to convert a “regular” enum-style finite state machine into a modern version based on std::variant from C++17. This technique allows you to improve design, work with value types and enhance code quality. States   Let’s start with a basic example: we want to track a game player’s health status we’d like to respond to events like “Hit by a monster” or “Healing bonus.

READ MORE...

Storage duration and Non-local Objects in C++

Updated:

C++ allows us to declare various forms of non-local objects: they usually live throughout the execution of the whole program. In this article, we’ll look at global variables, dynamic, and thread-local objects. We’ll also consider new features for safe initialization C++20. This text comes from my book “C++ Initialization Story”.

READ MORE...