Jonathan Boccara's blog

A Map with Two Types of Keys in C++

Published November 27, 2020 - 0 Comments

The need to associate keys to values is pretty common in computer programming. (That is a very general sentence, isn’t it?) In C++, the standard tools to achieve that are std::map and std::multimap that use comparisons on keys and std::unordered_map and std::unordered_multimap that use hashing. Boost adds flat_map, that offers a different performance trade-off and bimap to look […]

Announcing the Fluent C++ Store

Published November 20, 2020 - 0 Comments

You may have heard about it, and it is now official, the Fluent C++ store is open! Click on the store below to access it! Why a store Fluent C++ is a website for developers interested in the topic of expressive code in C++. And as developers, we tend to like cool t-shirts about programming! […]

How Lambdas Make Function Extraction Safer

Published November 13, 2020 - 0 Comments

One of the most interesting talks I saw when I was at CppCon 2019 was also one of the shortest ones. During one of the lightning talks evenings, Ezra (a.k.a. eracpp) demonstrated a technique to extract some code from a long function in a systematic way. Long functions are common in C++ legacy code, and extracting […]

How to Make a Copyable Object Assignable in C++

Published November 6, 2020 - 0 Comments

Some types in C++ have a copy constructor that doesn’t have the same semantics as their assignment operator (operator=). Take references, for example. References can be copied: int i = 42; int& r1 = i; int& r2 = r1; // r2 now points to i, like r1 But it doesn’t do the same thing as […]

How to Write Expressive Class Definitions

Published October 30, 2020 - 0 Comments

As developers, we read a lot of code. A typical code reading task is to scan through a class definition in a header file, in order to understand what the class is about. Sometimes, the purpose of the class does not appear as clearly as we would like. Sometimes, we need to spend a bit […]

An Attempt to Write Fallbacks With Expressive Code

Published October 23, 2020 - 0 Comments

When you need to initialise a value out of several possible choices and take the first valid one, the code can get verbose pretty quickly. Let’s take an example, inspired from a piece of legacy code I saw once. We start with a simple case, where we need to assign a value from one specific […]

The differences between tie, make_tuple, forward_as_tuple: How to Build a Tuple in C++?

Published October 16, 2020 - 0 Comments

Tuples are handy C++ components that appeared in C++11, and are a very useful help when programming with variadic templates. To make things even simpler, C++ offers not one but three helpers to build tuples and make our variadic template code more expressive: std::make_tuple, std::tie and std::forward_as_tuple. All three reflect in their name the fact that they put […]

Adapting STL Algorithms on Sets

Published October 9, 2020 - 0 Comments

This article is NWH, standing for Not Written Here. NWH is inspired from the NIH (Not Invented Here) syndrome which consists in refraining from using existing code from outside the company and reinventing the wheel every time. Just like it is good practice to look out for solutions developed elsewhere, we’re going to look at […]

How to Implement operator= When a Data Member Is a Lambda

Published October 2, 2020 - 0 Comments

In C++, some types of class members make it tricky to implement a copy assignment operator, operator=. For example references, const members, and… lambdas. Indeed, in the majority of cases, lambdas don’t have an operator=. (In case you’re wondering in what case lambdas have an operator=, it is in C++20 and when they don’t capture anything.) […]

1 5 6 7 8 9 45