Functions in std—Andrzej Krzemieński

The Standard reserves the right to change the signatures and overloads of the existing Standard Library functions in what is considered a backward compatible way:

Functions in std

by Andrzej Krzemieński

From the article:

Names of functions from the Standard Library used as pointers/references to functions can cause breakage in your code...

Functions of Variants are Covariant—Alfredo Correa

It's varying!

Functions of Variants are Covariant

by Alfredo Correa

From the article:

Sum types have a range of values that is the sum of the ranges of its parts. std::variant is the model representation of sum types in C++.

For example std::variant can hold an integer value (int state) or a double value (double state). The use of variant types provides support for polymorphism while maintaining value semantics.

There are only a few intrinsic functions that can be applied directly to an std::variant instance in C++; basically, only functions that probe or extract their current type state and value. Simple C++ functions over its component states cannot be applied directly to the variant since the type information needs to be probed before calling the corresponding function over the correct type.

Specific C++ functions can be applied through visitors. However, standard visitors are static and non-covariant, stopping polymorphism from propagating through function application.

A basic explanation of variants and their visitors can be found here.

Quick Q: use of constexpr in header file

Quick A: const in a header implicitely means static.

Recently on SO:

use of constexpr in header file

constexpr implies const and const on global/namespace scope implies static (internal linkage), which means that every translation unit including this header gets its own copy of PI. The memory for that static is only going to be allocated if an address or reference to it is taken, and the address is going to be different in each translation unit.

That implied static for const variables was introduced specifically to use const instead of #define in header files in C++ to define constants. Without static there would be multiple symbol definitions linker error if that header file is included in more than one translation unit which were linked together.

In C++17 you can also make it inline, so that there is only ever a single copy of PI if an address or reference to it is taken (i.e. not static). inline variables were introduced in C++17 to allow for header-only libraries with non-const variable definitions in the header files.

In other words, you should use constexpr for your constants in header files, if possible, otherwise const. And if you require the address of that constant to be the same everywhere mark it as inline.

Declarative Functional APIs – A.K.A. Abusing Lambda Parameters—Philippe Groarke

Take some time to clear your thoughts before reading!

Declarative Functional APIs – A.K.A. Abusing Lambda Parameters

by Philippe Groarke

From the article:

Functional APIs are a joy to work with. Not only do they help eliminate certain bug categories, but they tend to be very flexible and reusable. Today I present a technique that has emerged while I was simplifying some lambda based APIs. C++17 makes template meta-programming much more palatable, I dare not imagine what this would look like in C++11...

Should Span Be Regular?—Barry Revzin

Do you have an opinion?

Should Span Be Regular?

by Barry Revzin

From the article:

In my last post, I talked about the concept of Westie types (yes, I am trying to make this happen), what Regular means, and which of them are Regular. I went through an explanation for why means for span is not Regular and potentially why it should be. After lots of resulting conversations with several people (thanks Zach Laine, Nicole Mazzuca, Eric Niebler, John Shaw, Tim Song), I thought it was necessary to write a follow up with more details and more argument...

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