Articles & Books

Overload 159 is now available

ACCU’s Overload journal of October 2020 is out. It contains the following C++ related articles.

Overload 159 is now available

From the journal:

Virtual/Reality
By Frances Buontempo
Do we know what reality is? Frances Buontempo is no longer sure and now wonders if she’s a fictional character.

poly::vector – A Vector for Polymorphic Objects
By Ferenc Nándor Janky
Heterogeneous vectors can be slow. Janky Ferenc introduces a sequential container for storing polymorphic objects in C++.

Kafka Acks Explained
By Slanislav Kozlovski
Kafka’s configuration can be confusing. Slanislav Kozlovski helps us visualise this most misunderstood configuration setting.

Concurrency Design Patterns
By Lucian Tadu Teodorescu
Orchestrating concurrent tasks using mutexes is seldom efficient. Lucian Tadu Teodorescu investigates design patterns that help unlock concurrent performance.

C++ Modules: A Brief Tour
By Nathan Sidwell
C++20’s long awaited module system has arrived. Nathan Sidwell presents a tourist’s guide.

The Edge of C++
By Ferenc Deák
Everything has limits. Deák Ferenc explores the bounds of various C++ constructs.

Afterwood
By Chris Oldwood
Assume failure by default. Chris Oldwood considers various fail cases.

Quick Q: Why do I have to access template base class members through the this pointer?

Quick: in order to make x a dependent name, so that lookup is deferred until the template parameter is known

Recently on SO:

Why do I have to access template base class members through the this pointer?

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this->x. Why?

template <typename T>
class base {

protected:
    int x;
};

template <typename T>
class derived : public base<T> {

public:
    int f() { return this->x; }
};

int main() {
    derived<int> d;
    d.f();
    return 0;
}

Programming with C++20's Concepts [In Spanish] -- Daniel G Vergel

C++20 concepts dgvergel.blogspot.com

This post revisits the well-known Insertion Sort algorithm as a way to learn and practice several new C++20 features such as concepts, ranges, and projections.

Programming with C++20's Concepts

by Daniel G Vergel

About the article

The article, written in Spanish, follows very closely the way I introduce these topics to my Computer Engineering students at the European University (Madrid, Spain). As previous posts, it tries to mitigate the lack of educational materials on modern C++ currently available in my native language. Code examples are nevertheless self-explanatory and may be of interest to non-Spanish readers as well.

Semantic requirements in concepts

More concepts.

Semantic requirements in concepts

by Andrzej Krzemieński

From the article:

The word ‘concept’ in the context of C++ generic programming has two meanings. The first is more abstract: it is the notion from the domain of Generic Programming (GP) in general. GP is not tied to any specific language: it is an approach to writing programs, and concepts are part of this approach. In this sense concepts have been with us since the inception of the STL. The second meaning is the keyword concept in C++20 with its associated semantics: its goal is to approximate the more abstract notion of a concept from GP, and this works only to some extent. One notable difference is that concepts in GP specify semantic requirements on types they constrain, and C++ concepts cannot express them directly.

In this post we will see how semantic requirements in concepts can break your program if you don’t pay attention to them, and what can be done in C++20 concepts to account for semantic requirements...

Tricks with Default Template Arguments--Jonathan Müller

Did you know?

Tricks with Default Template Arguments

by Jonathan Müller

From the article:

Just like regular function parameters, template parameters can also have default parameters. For class templates, this behaves mostly just like default function arguments: if you pass fewer template arguments than required, default template arguments are used to fill the remaining places. However, for function templates, it gets more complicated as template parameters for functions can be deduced by the normal function arguments. This leads to some interesting side-effects. In particular, default arguments of template parameters don’t need to be put at the end!

Let’s take a look at a couple of things we can do with default template arguments...