Product Types for C++2x

Structured binding, tuple-like access, overload sets and pattern matching

Product types were/are everywhere, POD, aggregates, C-arrays, `std::tuple`, `std::pair`, `std::array`. It is just cumbersome to define an access interface. A lot of libraries have provided their own macros to reflect the product parts.

Structured binding (P0144) is friendly for end users and makes product types language based. Product type access (P0327) proposes a generic access to the elements of any product type and the number of elements. This interface is similar to the tuple-like access but takes in account all the types covered by Structured binding so we wouldn't need any more to make use of any macro to access any product type. This doesn't mean that the suer wouldn't customize their own product types.

We see product types as heterogeneous containers. Having a generic access interface opens the way to a whole set of algorithms.

Product types algorithms have heterogeneous functions instead of Callables. P0017 overloaded sets helps a lot in this context. Generic lambdas do as well. P0050 Overload function is the library solution to build the overloaded set explicitly.

In addition we need a way to build Product types in a generic way. P0091 helps at the user level but we need some kind of generic factory using type constructors (P0338).

Boost.Hana and Boost.Fusion have good example of what algorithms work well with heterogeneous containers. Some of them will be presented.

Last but not least product type feature is pattern matching (PM). Very often PM is associated to sum types and dynamic polymorphic types. However PM is also useful for product types, in particular patterns can be use as getters but also as filters.

Summarizing product types are a natural extension to the STL when we see them as heterogeneous containers.

Speaker: Vincente J. Botet Escriba

Slides


Go back