Jonathan Boccara's blog

A new post every Tuesday and Friday morning

Functors are not dead: the double functor trick

Published March 9, 2017 - 8 Comments

When C++11 arrived, lambdas were massively used in the places where functors used before. Lambdas are more elegant, involve less typing and can do pretty much all that functor did. Pretty much. But not quite. We covered how to make code expressive by using lambdas in a dedicated post, but there are a few use […]

Passing strong types by reference

Published March 6, 2017 - 16 Comments

On Fluent C++ we had already considered passing strong types by references, and realized that this wasn’t such a simple thing to do. To understand why, I suggest you read the problem statement in this previous post before starting this one, so that we are in line. So far the series on strong types contains […]

The Pi Day Challenge For The Most Expressive Code In C++

Published March 2, 2017 - 10 Comments

Each year, the fourteenth of March is marked by a very special event: Pi Day! It’s called this because in American notation, the 14th of March is 3/14. And during this day, the number Pi is celebrated all over the world in various ways. One notable way to celebrate it is bringing a pie to work or to university. […]

Predicates on ranges with the STL

Published February 23, 2017 - 6 Comments

In this episode of the STL learning resource, we see algorithms that can be used in a variety of contexts but that have one thing in common: they return a boolean characteristic of one or several ranges. The *_of series The STL provides 3 algorithms that indicates whether all, some, or none of the elements of a range satisfy […]

Strong lambdas: strong typing over generic types

Published February 20, 2017 - 5 Comments

This post is a new one in the series about strong types. I didn’t intend the series to contain more than 3 posts initially, covering the topics of strong types to make interfaces clearer and more robust. But I later encountered a need, still about strongly typing interfaces and that I shall describe in the motivation […]

Custom comparison, equality and equivalence with the STL

Published February 16, 2017 - 2 Comments

Let’s start with the following code excerpt: 

There are 2 sets of data represented by 2 sorted vectors v1 and v2, on which we apply a std::set_difference (see Algorithms on sets). This std::set_difference writes its output in results, with std::back_inserter ensuring that all outputs are push_back’d into results. One particularity though: a custom comparison operator […]

std::transform, a central algorithm

Published February 13, 2017 - 3 Comments

std::transform is a very useful algorithm. Let’s see what it can do. This post is part of the STL learning resource. std::transform on a range Essentially, std::transform applies a function to each element of a range: Here is its prototype:

As soon as you start working with the STL the need for std::transform appears. For example, to obtain the […]

What 70 people came up with on expressive code

Published February 6, 2017 - 7 Comments

Last week held the monthly meetup of Software Craftsmanship in my area. The organizer, Stéphane Bagnier, proposed a very original and interesting schedule for the evening. After a short series of brief and spontaneous presentations, any attendee could propose a topic he found worth spending time talking about, and then everyone got to vote. The 2 topics receiving the […]