Articles & Books

C++20: Heterogeneous Lookup in (Un)ordered Containers--Bartlomiej Filipek

Did you know?

C++20: Heterogeneous Lookup in (Un)ordered Containers

by Bartlomiej Filipek

From the article:

Would you like to gain 20…35 or even 50% speed improvements when searching in associative containers? In this blog post, we’ll explore a technique called “heterogenous access” that offers such impressive speedups. We’ll explore ordered containers, and the support for unordered collections added recently in C++20...

Virtual function calls in constructors and destructors

In different programming languages, the behavior of virtual functions differs when it comes to constructors and destructors. Incorrect use of virtual functions is a classic mistake. Developers often use virtual functions incorrectly. In this article, we discuss this classic mistake.

Virtual function calls in constructors and destructors

by Andrey Karpov

From the article:

So, what's the problem? You can find this information in any C++ programming book. The problem is that it's easy to forget about it! Thus, some programmers assume that foo and bar functions are called from the most derived C class. People keep asking the same question on forums: "Why does the code run in an unexpected way?" I think now you understand why it's easy to make a mistake in such code. Especially if you write code in other languages where the behavior is different. Let's look at the code fragment in C#.

Three reasons to pass std::string_view by value--Arthur O’Dwyer

You should.

Three reasons to pass std::string_view by value

by Arthur O’Dwyer

From the article:

It is idiomatic to pass std::string_view by value. Let’s see why.

First, a little background recap. In C++, everything defaults to pass-by-value; when you say Widget w you actually get a whole new Widget object. But copying big things can be expensive. So we introduce “pass-by-const-reference” as an optimization of “pass-by-value,” and we tell people to pass big and/or expensive things like std::string by const reference instead of by value.

But for small cheap things — int, char*, std::pair<int, int>, std::span<Widget> — we continue to prefer the sensible default behavior of pass-by-value.

Pass-by-value has at least three performance benefits over pass-by-(const)-reference. I’ll illustrate all three of them via string_view...

Strong Types for Safe Indexing in Collections – Part 2--Jonathan Boccara

Are you interested?

Strong Types for Safe Indexing in Collections – Part 2

by Jonathan Boccara

From the article:

In the previous article on strong types, we set out to find how to use strong types for safe indexing in collections.

More precisely, if we have two vectors with two indices to access them, how can we use strong types to make sure we use the right index for the right vector, and that we don’t swap them by mistake?

A capturing lambda can be a coroutine, but you have to save your captures while you still can

Will you use one?

A capturing lambda can be a coroutine, but you have to save your captures while you still can

by Raymond Chen

From the article:

We saw some time ago that capturing lambdas which are coroutines result in lifetime issues because the lambda itself returns at the first suspension point, at which point there’s a good chance it will be destructed. After that point, any attempt by the lambda body to access those captured variables is a use-after-free bug...