Articles & Books

The power of ref-qualifiers -- Andreas Fertig

overload171cover.pngNew in this month's Overload magazine:

The power of ref-qualifiers

by Andreas Fertig

From the article:

... What I have illustrated is that there is an issue with range-based for-loops. In (1), we call GetKeeper().items() in the head of the range-based for-loop. By doing this, we create a dangling reference.

ref-qualifiers to the rescue

Now, this brings us to ref-qualifiers. They are often associated with move semantics, but we can use them without move. However, we will soon see why ref-qualifiers make the most sense with move semantics.

A version of Keeper with ref-qualifiers looks like Listing 2...

The gotcha of the C++ temporaries that don’t destruct as eagerly as you thought -- Raymond Chen

RaymondChen_5in-150x150.jpgWorth waiting for:

The gotcha of the C++ temporaries that don’t destruct as eagerly as you thought

by Raymond Chen

From the article:

Forgetting to take a lock when updating variables is a common mistake. One way to make the mistake harder to make is to force the access to occur through some mechanism that proves that you possess the lock. Maybe something like this: ...

Deferred argument evaluation -- Joaquín M López Muñoz

joaquin.jpgWhy do now what you can do later (or not at all)?

Deferred argument evaluation

by Joaquín M López Muñoz

From the article:

Ideally, we'd like for try_emplace to not create the object except when really needed. What we're effectively asking for is some sort of technique for deferred argument evaluation. As it happens, it is very easy to devise our own: ...

The Singleton: The Alternatives Monostate Pattern and Dependency Injection -- Rainer Grimm

rainer_grimm.jpgHave you used the patterns?

The Singleton: The Alternatives Monostate Pattern and Dependency Injection

by Rainer Grimm

From the article:

So far, I have discussed in my previous posts the Singleton Pattern, and its pros and cons. One question is still open: What alternatives for the Singleton Pattern are available? Today, I write about the Monostate Pattern and Dependency Injection...

C++20 Concurrency: Barrier -- Gajendra Gulgulia

1*vXN7x9ljxB7JRw1ICFbA2Q.pngOne if by latch, two if by barrier:

C++20 Concurrency: Barrier

by Gajendra Gulgulia

From the article:

In this article, I’ll present a simple example of std::barrier by means of game players playing a hypothetical card game and go into the details of the api of std::barrier in another article...

Upcoming C++ User Group meetings in October 2022

The monthly listing on Meeting C++ about upcoming C++ User Group meetings:

Upcoming C++ User Group meetings in October 2022

by Jens Weller

From the article:

This month Meeting C++ online hosts some special events:

    Meeting C++ online job fair:
        4.10 C++ UG Meeting C++ online - Online C++ job fair (afternoon CEST)
        5.10 C++ UG Meeting C++ online - Online C++ job fair (evening CEST)
    20.10 C++ UG Meeting C++ online - October - AMA with Nicolai Josuttis
    25.10 C++ UG Meeting C++ online - Meeting C++ online book & tool fair
        With Bjarne Stroustrup and Klaus Iglberger

The Meetings
...

A talk with Jason Turner: the history of CppCast, and why it was shut down

In this article, we are going to talk to Jason Turner, one of the CppCast founders. From 2015 to 2022 CppCast had weekly conversations with C++ conference speakers, library authors, writers, ISO committee members, and more. Keep reading to learn about the CppCast backstory.

A talk with Jason Turner: the history of CppCast, and why it was shut down

by Uliana Grishina

From the article:

Hello, Jason! I'm sure our readers know what CppCast is and have come here to learn its story and fate. Before we begin, we'd like to hear more about you and what you're doing now. Chances are even regular CppCast listeners may know you just as "Jason, the podcast host." smile. So, could you tell us more about yourself? What do you do now and what did you do before you decide to stop CppCast?

the sad state of debug performance in C++ - - Vittorio Romeo

In this article, we’ll explore how C++’s abstraction model heavily relies on compiler optimizations, unveiling some unfortunate examples of unexpected performance loss. Afterwards, we will compare how the three major compilers (GCC, Clang, and MSVC) fare in this area, and we’ll discuss some potential future improvements or workarounds.

the sad state of debug performance in c++

by Vittorio Romeo

From the article:

C++ developers should know that `std::move(0)` is semantically the same as `static_cast<int&&>(0)`, and most of them would expect the compiler to generate no code for the move, even with optimizations disabled. Turns out that GCC 12.2, Clang 14.0, and MSVC v19.x all end up generating a call instruction. [...]

Reducing Signed and Unsigned Mismatches with std::ssize() -- Bartlomiej Filipek

Do you know about std::ssize()?

Reducing Signed and Unsigned Mismatches with std::ssize()

by Bartlomiej Filipek

From the article:

In this article, I’ll show another technique that avoids mixing signed and unsigned types.

In my article Integer Conversions and Safe Comparisons in C++20 we learned about cmp_* integer comparison functions that allow us to compare various types of integer types. The functions are safe because they help with mixing signed and unsigned types. In C++20, there’s another handy feature: the non-member std::ssize() function that returns a signed number of elements in a container.

Let’s see how to use it...