Articles & Books

Rvalues redefined--Andrzej Krzemieński

Evolution of semantics.

Rvalues redefined

by Andrzej Krzemieński

From the article:

In this post we will explore what I consider the most significant language change in C++17. I call it the most significant because it changes the way you design your resource-managing types and how you think about initialization. It is often called “guaranteed copy elision”, but I will not use that name (except for this single time) because it does not reflect what this feature is. C++ has completely changed the meaning of rvalue (actually, prvalue)...

std::accumulate vs. std::reduce--Simon Brand

Old vs new.

std::accumulate vs. std::reduce

by Simon Brand

From the article:

std::accumulate has been a part of the standard library since C++98. It provides a way to fold a binary operation (such as addition) over an iterator range, resulting in a single value. std::reduce was added in C++17 and looks remarkably similar. This post will explain the difference between the two and when to use one or the other...

How to Make SFINAE Pretty – Part 2: the Hidden Beauty of SFINAE--Jonathan Boccara

The next part.

How to Make SFINAE Pretty – Part 2: the Hidden Beauty of SFINAE

by Jonathan Boccara

From the article:

As we’ve seen in How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code, SFINAE in code is as pretty as a windmill in a field. That is, not very pretty.

But like a windmill, it’s useful. SFINAE helps deactivate a piece of template code depending on a condition, and that can be very convenient...

How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code

New series!

How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code

by Jonathan Boccara

From the article:

SFINAE is a bit like a windmill. It sits as a wart in the middle of an interface, BUT it’s useful to create elaborate static polymorphism, in particular before C++17 and if constexpr, and even in some use cases in C++17.

I thought we had to live with this tradeoff, until I watched a talk from Stephen Dewhurst at CppCon. In this inspring talk, Stephen shows how to turn SFINAE around to make it very expressive in an interface. Watching this talk changed my way of coding template interfaces...

Default-constructibility is overrated--Arthur O’Dwyer

What do you think?

Default-constructibility is overrated

by Arthur O’Dwyer

From the article:

The Ranges Technical Specification includes very many concept definitions (based on the Concepts TS), including for example Integral and Predicate. It also provides a concept named Regular which implements a variation on the “Regular” concept described by Alexander Stepanov in his paper '’Fundamentals of Generic Programming’’ (1998)...

Quick Q: typedef pointer const weirdness

Quick A: Don't hide pointers in typedefs.

Recently on SO:

typedef pointer const weirdness

Note that

typedef int* intptr;
const intptr x;

is not the same as:

const int* x;

intptr is pointer to int. const intptr is constant pointer to int, not pointer to constant int.

so, after a typedef pointer, i can't make it const to the content anymore?

There are some ugly ways, such as gcc's typeof macro:

typedef int* intptr;
intptr dummy;
const typeof(*dummy) *x;

but, as you see, it's pointless if you know the type behind intptr.