mp-units · part 06

Quantities and units on the road to C++29

· english· audience: mixed· AI-generated, reviewed by Filip Sajdak

Every demo in this series ran on a third-party library. The finale is about the plan to make that library unnecessary.

P3045, “Quantities and units library,” is the WG21 proposal to move what you have seen into the C++ standard library itself. It targets C++29. The proposal covers quantities with units in their types, kind safety, the affine space and formatting. The library mp-units is its reference implementation, so everything this series demonstrated is, in effect, a preview build of a possible std feature. The idea has been in front of the committee since P1935 first floated it in 2019, and P3045 is where it stands now.

The signature carries the physics

The core of the pitch fits in one function:

The signature avg_speed(quantity<si::metre>, quantity<si::second>) carries the physics. Callers may pass kilometres or hours, and the conversions are exact and automatic, but swapping the arguments does not compile. Compare that with the double avg_speed(double, double) every codebase has today, where the only defense is parameter naming and hope. Multiply that by every interface in a flight controller, a medical device or a trading system, and you have the case for standardization. Safety this fundamental should not depend on which third-party library a project happened to adopt.

P3045’s author and Poland’s committee seat

This finale has a local angle too. P3045’s lead author is Mateusz Pusz, a principal C++ architect from Gdańsk. He has been a voting member of the ISO C++ committee since 2017. He contributes to MISRA C++ and wrote accepted C++20 papers (heterogeneous lookup for unordered containers, P0919/P0920). He also co-founded the PKN subcommittee through which Poland became a P-member of the ISO C++ committee, which means Poland votes on what C++ becomes.

So the work toward a standard vocabulary for physical quantities is happening in the open, on GitHub, with a decade of library iterations behind it. Standardization is slow, and nothing is guaranteed until the final plenary vote. If P3045 lands, code like this series’ demos will need nothing but import std;.

Until then, the library is a find_package(mp-units) away, every episode’s demo is runnable in the Godbolt embeds, and the whole series is linked below.

The series:


Sources: P3045 latest revision · mp-units on GitHub · Mateusz Pusz.