Articles & Books

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.

Prepping Yourself to Conceptify Algorithms—Christopher Di Bella

In this article, we explore what concepts are, where they are useful, and how they are different to things that exist in vanilla C++17.

Prepping Yourself to Conceptify Algorithms

by Christopher Di Bella

From the article:

A very quick summary of this document is that constraints are requirements imposed on syntax, axioms are requirements imposed on semantics, and concepts are both constraints and axioms together.

...

Let’s build the EqualityComparableWith concept from the Ranges TS, from the ground up.

Using C++17 std::optional—Bartlomiej Filipek

See how and when std::optional from C++17 is useful:<img alt="" data-cke-saved-src="https://dl.dropboxusercontent.com/s/nv9s71vz8kq8pq3/stdoptusing.png?dl=0" src="https://dl.dropboxusercontent.com/s/nv9s71vz8kq8pq3/stdoptusing.png?dl=0" 400px;="" height:="" 128px;="" float:="" right;"="" style="height: 74px; width: 230px; float: right;">

Using C++17 std::optional

by Bartlomiej Filipek

From the article:

By adding the boolean flag to other types, you can achieve a thing called “nullable types”. As mentioned, the flag is used to indicate whether the value is available or not. Such wrapper represents an object that might be empty in an expressive way (so not via comments smile)

Non-Ownership and Generic Programming and Regular types, oh my!==Barry Revzin

Do you know about it?

Non-Ownership and Generic Programming and Regular types, oh my!

by Barry Revzin

From the article:

This post is about a specific collection of types in the C++ core language and standard library. I am not sure of a good way to name this collection, and some terms that come to mind come with their own baggage, so I’m going to for now group them together under an umbrella that is clearly widely unrelated to programming and call them Westie types (because, like my dog, they are awesome yet enigmatic).