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.
While 2020 was a crazy and hard year we were fortunate - C++20 was accepted and published, and the work on new features continues.
As usually every year, here’s my overview of the year: the standardization process, features, implementation, compilers, tools, books and more.
Other Reports:
2020 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012.
Last time in my blog post about How to Share Code with Const and Non-Const Functions in C++ I had a custom type declared and defined in one place (like in a header file). Recently, I tried to separate the declaration from implementation, and I got into a situation where one private function template was left.
I’m happy to announce a new update to my book on lambda expressions! A few pages more, and what’s important is that I heavily improved the consistency and some wording. All of that, thanks to valuable input from my readers and C++ experts. And today we’ll also have a look at one wording case - what’s a functor?
Lambda Capturing syntax allows us to quickly “wrap” a variable from the outside scope and then use it in the lambda body. We also know that under the hood the compiler translates lambda into a closure type… but what happens to those captured variables? Are they translated to public data members or private?
During the development of a container-like type, I run into the problem of how to share code between a const and non-const member functions. In this article, I’d like to explain what are the issues and possible solutions. We can even go on a bleeding edge and apply some C++20 features.
Runtime polymorphism usually connects with v-tables and virtual functions. However, in this blog post, I’ll show you a modern C++ technique that leverages std::variant and std::visit. This C++17 technique might offer not only better performance and value semantics but also interesting design patterns.
Last Update: 2nd Nov 2020 (Passing arguments, Build time benchmark, fixes).
Continuing the topic from last week, let’s dive into the topic of std::invoke. This helper template function helps with uniform syntax call for various callable object types and can greately reduce the complexity of our generic code.
Ranges and Projections In C++20 there are handful of rangified algorithms. As a simple example let’s say we want to sort a vector of integers:
When you see an article about new C++ features, most of the time you’ll have a description of major elements. Looking at C++17, there are a lot of posts (including articles from this blog) about structured bindings, filesystem, parallel algorithms, if constexpr, std::optional, std::variant… and other prominent C++17 additions.
But how about some smaller parts?
With the addition of Ranges and Concepts in C++20, our good old algorithm interfaces got super long “rangified” versions. For example, copy is now 4 lines long… and it’s just the declaration!
template <ranges::input_range R, std::weakly_incrementable O> requires std::indirectly_copyable<ranges::iterator_t<R>, O> constexpr ranges::copy_result<ranges::borrowed_iterator_t<R>, O> copy(R&& r, O result); How to decipher such a long declaration?
C++ grows very fast! For example, the number of pages of the C++ standard went from 879 pages for C++98/03 to 1834 for C++20! Nearly 1000 pages! What’s more, with each revision of C++, we get several dozens of new features. Have a look at my blog post with all C++17 features, it shows 48 items, and my C++20 reference card lists 47 elements!
Variadic templates and argument packs which are available since C++11 give flexibility in situations when you don’t know the number of inputs upfront. However, they are limited and can only appear at the end of the type sequence.
Have a look at today’s blog post from Jonathan Boccara, who describes a technique that might improve this situation.
Since a few months, I’ve been refactoring my old C++/OpenGL project. Thus far, I used compilers (MSVC and Clang), my knowledge or free tools. At some point, I also got a chance to leverage a solid static analysis tool - PVS-Studio. The tool helped me with identifying 8 critical issues not to mention good code style and performance enhancements (in total 137 warnings)