C++ at the end of 2020

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. Previous reports: 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012.

READ MORE...

Runtime Polymorphism with std::variant and std::visit

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).

READ MORE...

C++20 Ranges, Projections, std::invoke and if constexpr

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:

READ MORE...

17 Smaller but Handy C++17 Features

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.

READ MORE...

How To Stay Sane with Modern C++

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!

READ MORE...

Lambda Week: Tricks

We’re on the last day of the lambda week. We have all the essential knowledge, and now we can learn some tricks! The Series This blog post is a part of the series on lambdas: The syntax changes (Tuesday 4th August) Capturing things (Wednesday 5th August) Going generic (Thursday 6th August) Tricks (Friday 5th August)(this post) +[]() Have a closer look:

READ MORE...

Lambda Week: Going Generic

We’re in the third day of the lambda week. So far, you’ve learned basic syntax and how to capture things. Another important aspect is that lambdas can also be used in the “generic” scenarios. This is especially possible since C++14 where we got generic lambdas (auto arguments), and then in C++20, you can even specify a template lambda!

READ MORE...

Lambda Week: Capturing Things

We’re in the second day of the lambda week. Today you’ll learn about the options you have when you want to capture things from the external scope. Local variables, global, static, variadic packs, this pointer… what’s possible and what’s not? The Series This blog post is a part of the series on lambdas:

READ MORE...

Lambda Week: Syntax changes, C++11 to C++20

Let’s start the week with Lambda Expressions. The plan is to have a set of concise articles presenting core elements of lambda expressions. Today you can see how the syntax has evolved starting since C++11 and what are the latest changes in C++20. The Series This blog post is a part of the series on lambdas:

READ MORE...

See My Talk: Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes

Last Tuesday, 21th July, I had a pleasure to talk about [[no_unique_address]] on our Cracow C++ User Group online meeting. Here are the slides and additional comments from the presentation. Some Issues Our C++ Cracow User group: https://www.meetup.com/C-User-Group-Cracow/ We also experienced the problems related to COVID situation, and for two months - in March and April, we had to cancel our regular monthly meetings.

READ MORE...