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.
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?
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:
In this blog post, we’ll look at several different view/reference types introduced in Modern C++. The first one is string_view added in C++17. C++20 brought std::span and ranges views. The last addition is std::mdspan from C++23.
Let’s start.
String View (C++17) The std::string_view type is a non-owning reference to a string.
Learn how the overload pattern works for std::variant visitation and how it changed with C++20 and C++23.
While I was doing research for my book and blog posts about C++17 several times, I stumbled upon this pattern for visitation of std::variant:
template<class... Ts> struct overload : Ts... { using Ts::operator()...; }; template<class.
Today, I’ll show you my review of a cool book, “Beautiful C++,” written by two well-known C++ experts and educators: Kate Gregory and Guy Davidson. The book’s unique style gives us a valuable perspective on effective and safe C++ code.
Let’s see what’s inside.
Disclaimer: I got a free copy from the publisher.
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.
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.
In this article, we’d shed some light on the implementation of ranges::reverse_view and std::views::reverse. We’ll compare them to understand the differences between views and their adaptor objects.
Let’s jump in.
ranges::reverse_view and std::views::reverse in Action Let’s look at an example to understand how these views work. Assume we have a range r of integers from 1 to 5.
Lots of practical examples, general programming, software development techniques, OOP, parallel algorithms, plus C++ to combine it all into working applications. This is a short introduction to the book “Introduction to Programming with C++” by Prof. Boguslaw Cyganek, an excellent book for students who start their journey with system coding.
In my last article, we discussed Finite State Machines based on std::variant and some cool C++17 techniques. Today I want to go further and show you an example of a Vending Machine implementation.
Here’s the previous article Finite State Machine with std::variant - C++ Stories States & Events Here’s a basic diagram that illustrates how the machine is going to work:
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.
Last week the ISO committee met in Varna to discuss some of the first batch of C++26 features. It’s an excellent occasion to shed some light on the latest status and interesting C++ proposals.
Let’s start!
By the way: This will be my first blog post with the #cpp26 tag!