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.
With Modern C++ and each revision of the Standard, we get more comfortable ways to initialize data members. There’s non-static data member initialization (from C++11) and inline variables (for static members since C++17).
In this blog post, you’ll learn how to use the syntax and how it has changed over the years.
This article is the third and the last one in the mini-series about ranges algorithms. We’ll look at some sorting, searching, and remaining algorithms. We’ll also have a glimpse of cool C++23 improvements in this area.
Let’s go.
Before we start Key observations for std::ranges algorithms:
Ranges algorithms are defined in the <algorithm> header, while the ranges infrastructure and core types are defined in the <ranges> header.
C++11 has been around for around 11 years and C++14 for 8. From my experience, I see that even today, many companies struggle to use those standards in production in the most efficient way. As always, with new stuff came benefits, risks, and increased learning effort. Fortunately, with a new book written by top C++ Experts, we have a solid guide on what is safe and what might be problematic in Modern C++.
In the previous article in the Ranges series, I covered some basics and non-modifying operations. Today it’s time for algorithms like transform, copy, generate, shuffle, and many more…. and there’s rotate as well :)
Let’s go.
Before we start Key observations for std::ranges algorithms:
Ranges algorithms are defined in the <algorithm> header, while the ranges infrastructure and core types are defined in the <ranges> header.
With C++17, you can now use more sophisticated algorithms for pattern searches! You’ll have more control and a promising performance boost for many use cases. This article shows primary usage and runs a benchmark comparing the new techniques.
May 2022 Updates: added notes about C++20 and constexpr algorithms, updated the benchmark and compared against std::ranges::search and custom strchr versions.
C++20’s Ranges offer alternatives for most of <algorithm>'s'. This time I’d like to show you ten non-modifying operations. We’ll compare them with the “old” standard version and see their benefits and limitations.
Let’s go.
Before we start Key observations for std::ranges algorithms:
Ranges algorithms are defined in the <algorithm> header, while the ranges infrastructure and core types are defined in the <ranges> header.
With C++20, we have a new approach to writing algorithms and composing them. The significant question is their performance. Are they faster or slower than the standard C++ algorithms we have known for decades? Let’s find out in this article.
I’ll show you three use cases with performance results, and also we’ll compare build times.
In this blog post, I’ll show and explain a strange-looking error about tuple_size_v and instantiation for \n character. You’ll see some tricky parts of SFINAE and how the compiler builds the overload resolution set.
Let’s go.
A surprising error When doing experiments with tuple iteration (see part one and part two) I got this strange-looking compiler error:
In January, I was lucky to get a relatively new book on Modern C++! This time it’s not aimed at experts but rather at the beginner level. It’s called “Modern C++ for Absolute Beginners,” written by Slobodan Dmitrović. I think it might be a valuable resource for job interviews.
Let’s see what’s inside.
Boolean parameters in a function might be misleading and decrease its readability. If you have a poorly named function like:
DoImportantStuff(true, false, true, false); As you can imagine, it’s not clear what all those parameters mean? What’s the first true? What does the last false mean? Can we improve code in such cases?
In the previous article on the tuple iteration, we covered the basics. As a result, we implemented a function template that took a tuple and could nicely print it to the output. There was also a version with operator <<.
Today we can go further and see some other techniques. The first one is with std::apply from C++17, a helper function for tuples.
If you have a standard container, it’s easy to use a range-based for loop and iterate over its elements at runtime. How about std::tuple? In this case, we cannot use a regular loop as it doesn’t “understand” tuple’s compile-time list of arguments. That’s why in this article, I’ll show you a few techniques you can use to run through all tuple’s entries.