Unleashing the Power of C++ Templates with mp-units: Lessons learned and a new library design

Mateusz Pusz

90 minute session
10:45-12:15, Thursday, 29th June 2023

This lecture presents how Modern C++ enables exciting features and attractive new design possibilities. The presented library pushes the boundaries of Modern C++ interfaces. Mateusz will present novel ways of using C++ templates benefiting from C++20 and C++23 features.

mp-units is a Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation. It heavily uses C++20 features like concepts and values of class types used as non-type template parameters (NTTPs). Also, it introduced a new powerful technique called the Downcasting Facility.

During the talk, the library's author will describe the significant challenges with the initial design. He will explain the issues with the Downcasting Facility and why user-defined literals (UDLs) are not a good choice for creating quantities, and what the alternatives are. Mateusz will also describe additional requirements that couldn't be addressed with the previous framework and present how the new design addresses them.

In the end, we will discuss potential C++ language features that could be helpful to improve the design of this and similar libraries.

Modern C++

Mateusz Pusz