Articles & Books

Improving my C++ time queue -- Marius Elvert

Tick, tock...

Improving my C++ time queue

by Marius Elvert

From the article:

Another code snippet that can be found in a few of my projects is the “time queue”, which is a simple ‘priority queue’ style data structure that I use to defer actions to a later time. ...

Lifetime extension of temporary objects in C++: common recommendations and pitfalls

After reading this article, you will learn the following: ways to extend the lifetime of a temporary object in C++, various tips and tricks; pitfalls of the lifetime extension that a C++ programmer may face.

Lifetime extension of temporary objects in C++: common recommendations and pitfalls

by Evgeny Neruchek

From the article:

You can extend the lifetime of a temporary array by referencing one of its elements. C++ has a special mechanism for this. But I would recommend you using it only in the disputes with your co-workers (and maybe in metaprogramming with the old C++ standards), since this mechanism is not so easy-to-use. However, using this mechanism does not result in dangling references, and the lifetime of the temporary array is extended to the lifetime of the reference to its element.

Convenient Unicode UTF-8 UTF-16 Conversion Functions for Windows C++ Code -- Giovanni Dicanio

In Windows C++ programming many times there's a need to convert text between UTF-8 and UTF-16 encodings.

Convenient Unicode Conversion Functions for Windows C++ Code

by Giovanni Dicanio

From the article:

I published on GitHub a header-only library (Utf8Conv) that implements some convenient functions to convert text between UTF-8 and UTF-16 Unicode encodings.

I developed the library using Visual Studio 2019 with C++17 features enabled.

The Bridge Pattern -- Rainer Grimm

Of Bridges and Pimpls:

The Bridge Pattern

by Rainer Grimm

From the article:

In C++, a simplified version of the Bridge Pattern is often used. ... The key idea of the Pimpl Idiom is that the implementation of the class is hidden behind a pointer. Here is a recipe for implementing the Pimpl Idiom: ...

 

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