It has been 1.5 years since the last major update on the ISO C++ standardization
progress here. It is not that I got lazy , but there was really not much
to share.
This time, things were different. We achieved a nearly unprecedented success.
Probably not many people expected it, and I definitely did not! 🎉
Physical quantities and units libraries exist primarily to prevent errors at compile time.
Some of them focus only on dimensional analysis and unit conversions. Others go further and
prevent representation errors, semantic misuse of same-dimension quantities, and even errors
in the mathematical structure of equations.
This article describes six safety levels that a quantities and units library can provide,
with examples for each of them. Then it compares how leading C++ libraries and units
libraries from other languages score across those levels, together with their performance
and memory costs.
Two of the upper levels are the focus here. Quantity kind safety
distinguishes dimensionally equivalent concepts such as work vs. torque, or Hz vs. Bq.
Quantity safety enforces correct quantity hierarchies and scalar/vector/tensor
mathematical rules. Both are well-established concepts in metrology and physics, and both
remain widely overlooked in the C++ ecosystem. They go well beyond dimensional analysis and
prevent subtle semantic errors that unit conversions alone cannot catch.
The mp-units documentation has two new sections: tutorials and hands-on workshops for
learning type-safe physical quantities and units. The tutorials start at the first quantity
you create, and the workshops go on to the more advanced patterns.
The mp-units documentation now has an automated systems reference generator. It
extracts all quantities, units, dimensions, and their relationships directly from the
library's C++ source code and documents them.
A new product version can be obtained from
GitHub
and
Conan.
I initially had different plans for this release, but during development, it became
clear that the new major feature I was working on was too large and would require
breaking changes. This put me off track, and unfortunately, the mp-units development
slowed down recently 😞
It also turned out that I got laid off, so now I depend solely on my C++ trainer's career
to earn money to live. Fortunately, I delivered many in-house C++ trainings to my
customers this year, and I hope this will also be the case in the upcoming 2026. I was
also busy preparing for new talks and classes at this year's C++ conferences.
Having that much on my plate, a break from mp-units was needed to not burn out on the
way. But hopefully I am back now, and I plan to continue working on long-awaited features.
This release contains many small patches and improvements.
This post describes the most significant changes while a much longer list of the
changes introduced by the new version can be found in our
Release Notes.
Until now, mp-units forced users to choose between points, which do not provide
arithmetic, and deltas, which do not provide physical semantics. Neither of them covers
the most common case, which is a non-negative absolute amount.
An absolute quantity represents an absolute amount of a physical property,
measured from a true, physically meaningful zero. Examples include mass in kilograms,
temperature in Kelvin, or length in meters (as a size, not a position). Such
quantities live on a ratio scale and are anchored at a physically meaningful zero.
Negative values are typically meaningless.
Absolute quantities stand in contrast to:
Affine points (e.g., \(20\ \mathrm{°C}\), \(100\ \mathrm{m}\ \mathrm{AMSL}\)) are values
measured relative to an arbitrary or conventional origin.
Deltas (e.g., \(10\ \mathrm{K}\), \(–5\ \mathrm{kg}\)) are differences between two values.
Arithmetic on absolute quantities behaves like ordinary algebra: addition, subtraction,
and scaling are well-defined and map naturally to physical reasoning. This article
proposes making absolute quantities the default abstraction in mp-units V3,
reflecting how scientists express equations in practice.
All quantities and units libraries need to be unit-safe. Most of the libraries
on the market do this correctly. Some of them are also dimension-safe, which
adds another level of protection for their users.
mp-units is probably the only library on the market that additionally is
quantity-safe. This gives a new quality and possibilities. I've described the
major idea behind it, implementation details, and benefits to the users in the
series of posts about the International System of Quantities.
However, this is only the beginning. We've always planned more and worked on the
extensions in our free time. In this post, I will describe:
What a quantity character is?
The importance of using proper representation types for the quantities.
The power of providing character-specific operations for the quantities.
Discuss implementation challenges and possible solutions.
The Wrocław 2024 meeting was another efficient step in the standardization of
this library. We've spent the entire day on the joint LEWGI and SG6 discussion
and got lots of feedback. We've also introduced std::fixed_string to LEWG for
C++26.
A new product version can be obtained from
GitHub and
Conan.
This release was unexpected. We planned a significant new feature to happen next, but while
preparing for it and writing API Reference documentation, we made so many vital fixes and
improvements that we decided they deserve a dedicated release first.
This post describes the most significant improvements while a much longer list
of the changes introduced by the new version can be found in our
Release Notes.