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.
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.
In this article, we’ll look at a super handy ranges view in C++23 - views::zip. In short, it allows you to combine two or more ranges and iterate through them simultaneously. Let’s see how to use it.
Basic If you have two (or more) separate containers and you want to iterate through them “in parallel,” you can write the following code:
C++20 Ranges algorithms have an excellent feature called “Projection”. In short, it’s a callable applied on each range element before further processing. In this article, I’ll show you a couple more examples of this handy feature.
Intro According to the C++20 Standard: [defns.projection]:
projection: transformation that an algorithm applies before inspecting the values of elements
std::format added in C++20 is a powerful helper for various text formatting tasks. In this blog post, we’ll have fun and print some tables with it. You’ll see the “old” C++17 version and compare it against the C++20 style.
std::format excercise As an exercise to learn about std::format, we can try printing some more advanced structures than just “Hello World”.
In C++11, we got a handy way to initialize various containers. Rather than using push_back() or insert() several times, you can leverage a single constructor by taking an initializer list. For example, with a vector of strings, you can write:
std::vector<std::string> vec { "abc", "xyz", "***" }; We can also write expressions like:
Around the time C++17 was being standardized I saw magical terms like “discriminated union”, “type-safe union” or “sum type” floating around. Later it appeared to mean the same type: “variant”.
Let’s see how this brand new std::variant from C++17 works and where it might be useful.
Update in early 2023 with notes about C++20, C++23 and other smaller refinements/wording.
I must admit that some previous years for C++ might feel a bit “boring” and “stable”. New features, new standard every three years, meetings, conferences… life as usual (apart from some additional World/Economy/public Health events…). This year seems different as it looks like a “breakpoint” in the history of C++… and who knows where it will lead us.
I’m happy to announce that my new book on C++ Initialization is published and finished!
Have a look at the background story and how to get it.
Updates: Go to the latest updates from 23rd Dec here, 30 new pages added!
Note: Initially, the book was called “Data Member Initialization in Modern C++”, but in September 2022, I updated it heavily and changed the title.
Structured bindings are a C++17 feature that allows you to bind multiple variables to the elements of a structured object, such as a tuple or struct, in a single declaration. This can make your code more concise and easier to read, especially when working with complex data structures. In this blog post, we will look at the basic syntax of this cool feature, its use cases, and even some real-life code examples.
It’s almost the end of the year! As usual, I started writing my “year” summary that I will publish on the 31st of December.
The survey has completed, thank your for 649 votes!
Stay tuned for the annual summary article on Dec 31st!
Yet, this article won’t be possible without your input!
As of C++20, we have four keywords beginning with const. What do they all mean? Are they mostly the same? Let’s compare them in this article.
const vs constexpr const, our good old fried from the early days of C++ (and also C), can be applied to objects to indicate immutability.