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.
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!
A few years ago (see here, I showed an interesting implementation for self-registering classes in factories. It works, but one step might be at the edge of Undefined behavior. Fortunately, with C++20, its new constinit keyword, we can update the code and ensure it’s super safe.
Intro Let’s bring back the topic:
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”.
Last time I showed a couple of questions about initialization. Try them here if you haven’t already. In this article, I’ll show you the answers and add more notes about initialization in C++.
About I selected the following questions from 25 questions that you can find in my C++ Initialization Story book:
Do you know the answers to those ten questions about Initialization in Modern C++?
About I selected the following questions from 25 questions that you can find in my C++ Initialization Story book:
Print version @Amazon
C++ Initialization Story @Leanpub Moreover, in the book, you can find a few coding exercises to practice skills.
I’m thrilled to announce the print/paperback edition of “C++ Initialization Story!” After nearly a year of updates and enhancements for the electronic version, this comprehensive resource is now complete! You can purchase the book in a variety of formats, and to celebrate this major update, I’m hosting a giveaway where you can get the book for free :)
Conceptually a Range is a simple concept: it’s just a pair of two iterators - to the beginning and to the end of a sequence (or a sentinel in some cases). Yet, such an abstraction can radically change the way you write algorithms. In this blog post, I’ll show you a key change that you get with C++20 Ranges.