Search Results for: strong types

Strong Types for Safe Indexing in Collections – Part 1

Published October 31, 2021 - 0 Comments

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 […]

Strong Types on Collections

Published July 26, 2019 - 0 Comments

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 […]

Making Strong Types Implicitly Convertible

Published January 5, 2018 - 0 Comments
Strong types implicit conversions

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 […]

Using Strong Types to Return Multiple Values

Published November 10, 2017 - 14 Comments

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 […]

Calling Functions and Methods on Strong Types

Published November 7, 2017 - 7 Comments
Functions methods strong types C++

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 […]

Making Strong Types Hashable

Published May 30, 2017 - 5 Comments

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: inheriting the underlying type’s functionalities

Published May 23, 2017 - 5 Comments

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 […]

Good news: strong types are (mostly) free in C++

Published May 5, 2017 - 3 Comments

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 […]

1 2 3 18