In the previous article on strong types, we set out to find how to use strong types for safe indexing in collections. More precisely, if we have two vectors with two indices to access them, how can we use strong types to make sure we use the right index for the right vector, and that […]
Strong types make code safer and more expressive by using the type system to identify individual objects. For example, to instantiate a class Rectangle with a certain width and height, we could write this: Rectangle myRectangle{4, 5}; But then it isn’t clear for a reader of the code which of the two parameters is the […]
Do we need a special strong type library for collections? Or can we strongly type collections like we do for any object? If you’re joining us right now and haven’t read the previous articles on strong types, long story short, a strong type is a type used instead of another one in order to add […]
A couple of weeks ago I had the opportunity to speak at Meeting C++, in Berlin. This talk has come out on Youtube recently, and I’d like to share it with you. This presentation sums up the fundamental aspects of strong typing in C++ as I see it. I hope you enjoy it! Of course, […]
Strong types and implicit conversions, doesn’t this sound like incompatible features ? It can be argued that they are compatible, in fact. We saw why it could be useful to inherit from the underlying type’s features, and if the underlying type is implicitly convertible to something then you might want to inherit that feature too […]
We’ve seen how strong types helped clarifying function interfaces by being explicit about what input parameters the function expected. Now let’s examine how strong types help clarifying functions that return several outputs. We’ll start by describing the various ways to return several outputs from a function in C++, and then see how strong types offer an […]
Strong types are a way to put names over data in code in order to clarify your intentions, and the more I work on it the more I realize how deep a topic that is. So far we’ve seen the following subjects in our series on strong types: Strongly typed constructors Strong types for strong interfaces […]
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 […]
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 […]
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 […]