InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now. Learn more →
Top 5 C++ physical-unit Projects
-
Project mention: Python type hints may not be not for me in practice | news.ycombinator.com | 2024-11-27
I suspect C++ still comes the closest to what you’re asking for today, at least among mainstream programming languages.
Matrix dimensions are certainly doable, for example, because templates representing mathematical types like matrices and vectors can be parametrised by integers defining their dimension(s) as well as the type of an individual element.
You can also use template wizardry to write libraries like mp-units¹ or units² that provide explicit representations for numerical values with units. You can even get fancy with user-defined literals so you can write things like 0.5_m and have a suitably-typed value created (though that particular trick does get less useful once you need arbitrary compound units like kg·m·s⁻²).
Both of those are fairly well-defined problems and the solutions available do provide a good degree of static checking at compile time.
IMHO, the range question is the trickiest one of your three examples, because in real mathematical code there are so many different things you might want to constrain. You could define a parametrised type representing open or closed ranges of integers between X and Y easily enough, but how far down the rabbit hole do you go? Fractional values with attached precision/error metadata? The 572 specific varieties of matrix that get defined in a linear algebra textbook, and which variety you get back when you compute a product of any two of them?
¹ https://mpusz.github.io/mp-units/
² http://nholthaus.github.io/units/
-
InfluxDB
InfluxDB – Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
-
SI
A header only C++ library that provides type safety and user defined literals for physical units (by bernedom)
-
au
A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience. (by aurora-opensource)
-
Units
A run-time C++ library for working with units of measurement and conversions between them and with string representations of units and measurements (by LLNL)
-
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
C++ physical-units discussion
C++ physical-units related posts
-
TIL the USA was supposed to adopt the metric system but the ship carrying the standardized meter and kilogram was hijacked by pirates in 1793 and the measurements never made it to the States
-
SI Unit division not working
-
C++ lib for handling SI units
-
Just discovered C++ has keywords 'and'/'or'/'not' etc.
-
LLNL/units - runtime C++ unit conversion library
-
A note from our sponsor - InfluxDB
www.influxdata.com | 15 May 2025