There is a part of C++ developers that appreciate template metaprogramming. And there are all the other C++ developers. While I consider myself falling rather in the camp of the aficionados, I’ve met a lot more people that don’t have a strong interest for it, or that even find it downright disgusting, than TMP enthusiasts. Which camp do you […]
Strong types are types that are built over primitive types, and add meaning to them. My purpose today is two-fold: showing you how to write an STL-compliant hash function for custom types so that they can be used in unordered containers such as std::unordered_map, making a hash function available for strong types. For more about the motivation […]
Strong types are a way to add a meaning to objects by giving them a meaningful name, by using types. This lets the compiler, human beings, and developers understand better the intent of a piece of code. We’ve been exploring strong types on Fluent C++. I focus here on how to define strong types conversions. If you want to catch […]
This post is part of the series on strong types: Strongly typed constructors Strong types for strong interfaces Passing strong types by reference Strong lambdas: strong typing over generic types Good news: strong types are (mostly) free in C++ Inheriting functionalities from the underlying type Making strong types hashable Converting strong units to one another Metaclasses, the […]
In this final episode of the series on the Curiously Recuring Template Pattern, let’s see an implementation that makes it easier to write CRTP classes. In case you missed an episode in the series, here they are: The CRTP, episode One: Definition The CRTP, episode Two: What the CRTP can bring to your code The CRTP, episode […]
After having defined the basics on the CRTP in episode #1 of the series, let’s now consider how the CRTP can be helpful in day-to-day code. The episodes in this series are: The CRTP, episode One: Definition The CRTP, episode Two: What the CRTP can bring to your code The CRTP, episode Three: An implementation helper for […]
The Curiously Recurring Template Pattern (CRTP) is a C++ idiom whose name was coined by James Coplien in 1995, in early C++ template code. The “C” in CRTP made it travel the years in the C++ community by being this: a Curiosity. We often find definitions of what CRTP is, and it is indeed an […]
Code sprawling over multiple lines of code and getting drowned into low-level details is typically hindering expressiveness. But cramming everything into one single statement is not always the right thing to do either. As an example, here is a buggy code that was spotted and fixed by my colleague Benoît (context has been obfuscated in […]
Strong types are a simple and efficient tool for improving code expressiveness, by letting you express your intentions better to both the compiler and to your fellow human companions. This post is part of the series about strong types, that keeps growing because it is such a rich topic: Strongly typed constructors Strong types for strong […]
Comments are one of these places where religion meets technology. On one side there are the firm believers that good code is commented code, and on the other side stand the devout to the scarcest commenting chapel. We can’t discuss expressive code and not talk about comments at some point. Is code expressiveness an alternative to comments, or are the […]