Articles & Books

strong_typedef - Create distinct types for distinct purposes--Anthony Williams

A common problem with a common solution made easier.

strong_typedef - Create distinct types for distinct purposes

by Anthony Williams

From the article:

One common problem in C++ code is the use of simple types for many things: a std::string might be a filename, a person's name, a SQL query string or a piece of JSON; an int could be a count, an index, an ID number, or even a file handle. In his 1999 book "Refactoring" (which has a second edition as of January 2019), Martin Fowler called this phenomenon "Primitive Obsession", and recommended that we use dedicated classes for each purpose rather than built-in or library types...

Heterogeneous Lookup in Ordered Containers, C++14 Feature--Bartlomiej Filipek

Did you know?

Heterogeneous Lookup in Ordered Containers, C++14 Feature

by Bartlomiej Filipek

From the article: 

If you have a map of strings, like std::map<std::string, int> m; and you want to find some element by m.find("abc"). Do you have to pay the price and construct a std::string object? Can you optimize it?

Let’s have a look at one feature enabled in C++14 that might help optimize such container access...

Quick Q: When should I make explicit use of the `this` pointer?

Quick A: to disambiguate.

Recently on SO:

When should I make explicit use of the `this` pointer?

Usually, you do not have to, this-> is implied.

Sometimes, there is a name ambiguity, where it can be used to disambiguate class members and local variables. However, here is a completely different case where this-> is explicitly required.

Consider the following code:

template<class T>
struct A {
   int i;
};

template<class T>
struct B : A<T> {

    int foo() {
        return this->i;
    }

};

int main() {
    B<int> b;
    b.foo();
}

If you omit this->, the compiler does not know how to treat i, since it may or may not exist in all instantiations of A. In order to tell it that i is indeed a member of A<T>, for any T, the this-> prefix is required.

Note: it is possible to still omit this-> prefix by using:

template<class T>
struct B : A<T> {

    using A<T>::i; // explicitly refer to a variable in the base class

    int foo() {
        return i; // i is now known to exist
    }

};

Core C++ 2019 Trip Report--Anastasia Kazakova

It's trip report time!

Core C++ 2019 Trip Report

by Anastasia Kazakova

From the article:

More and more C++ events, community meetups, and conferences are appearing around the globe. 2019 is definitely looking like a year for new C++ conferences. Take, for example, C++ on Sea (UK, in February) or the upcoming CPPP (France, in June). Even C++ Russia now has two editions per year – one in Moscow and one in St. Petersburg. And, finally, there’s the event we just visited – Core C++, held in Tel Aviv, Israel...

C++ Core Guidelines: The Standard Library--Rainer Grimm

The guidelines explained further.

C++ Core Guidelines: The Standard Library

by Rainer Grimm

From the article:

Curiously, there is no section to the algorithms of the standard template library (STL) in this chapter. Curiously, because there is a proverb in the C++ community: If you write an explicit loop, you don't know the algorithms of the STL. Anyway. Only for completeness, let me start with the first three rules which provide not much beef...

Report from using std::cpp 2019

The statitistics.

Report from using std::cpp 2019

From the article:

On March, 7th, we had the sixth edition of using std::cpp (the C++ conference in Spain). The conference was again a on-day free event, and as every other year it was hosted at the Higher Polytechnic School of University Carlos III of Madrid in Leganés.

As many other years roughly 200 participants attended the conference. Most of the attendees were coming from industry...

C++17 STL Parallel Algorithms - with GCC 9.1 and Intel TBB on Linux and macOS--Paul Silisteanu

It's coming!

C++17 STL Parallel Algorithms - with GCC 9.1 and Intel TBB on Linux and macOS

by Paul Silisteanu

From the article:

GCC 9.1 has support for C++17 parallel algorithms by using the Intel TBB library. In this article, I will show you how to build Intel TBB from sources on your machine and how to sort a vector of random numbers in parallel using C++17 std::sort...

ACCU Trip report--Kate Gregory

Sweet and short.

ACCU Trip report

by Kate Gregory

From the article:

In early April I was lucky enough to go to Bristol in the UK for the annual ACCU conference. This has been an aspirational conference for me, one I attended before speaking at and am always delighted to attend. This year I was invited to keynote, and it turned out to be the closing keynote, which meant I was not done with all my talks until the conference was over! Nevertheless I enjoyed the week tremendously...

Curried Objects in C++--Jonathan Boccara

Abstraction to the rescue.

Curried Objects in C++

by Jonathan Boccara

From the article:

Curried objects are like facilitators. They consist in intermediary objects between a caller and a callee, and helps them talk to each other in a smooth way. This ability makes the code simpler and easier to read...