Draft: Proposal for mp-units library inclusion

This MR prototypes the use of mp-units to provide strongly typed units and quantities for ns-3. This proposal, if accepted, would close previous MRs on this topic !2085 (nholthaus/units) and !2673 (si-units-v2).

In 2023, Peter suggested to investigate mp-units because it was a candidate for C++ standardization. At the time, C++-26 or possibly C++-29 seemed a bit far off, and mp-units required at least C++-20 support (which we did not have back then).

Now it is 2026, and C++-29 is not so far off, and we support C++-20 compilers. mp-units is still reportedly a candidate for C++-29. As a result, I decided to have another look at this.

The main benefits that I perceive, over !2085 and !2673, are:

  1. provides a clean path to future standard library inclusion. The other libraries under consideration would likely incur some portability/compatibility issues because the mp-units syntax is different.
  2. mp-units appears to possibly offer a path for compatibility of ns3::Time class, which the other proposals do not. This would, however, require that we give up the runtime resolution capability of ns3::Time and make it compile-time. I have not tried to port ns3::Time to this; it is just speculation based on the ability to set the time representation type as int64_t.

It had some similar drawbacks in lack of logarithmic power support, but similar ns-3 wrappers can do the job until if/when that support is added. This MR includes such support for dBm and dB. mp-units has some other benefits, including C++-20 concepts for better error messages, std::chrono interoperability, and the syntax for raw value extraction seems to me to be a bit safer (self-documenting).

I copied the latest mp-units release (2.5.0) into the third-party folder; if it became part of the standard library, we could eventually remove it from there.

I re-created the tests and example program that I wrote for nholthaus/units (!2085) and did not encounter problems. The example program is kind of like a demo, and I temporarily copied the output of it into a Markdown file in this directory (commit would be removed before merging). Please see the file posted in the top-level-directory (link here); it should give you a feel for how it would work in practice.

I would like to try to agree on this and merge it before end of March, and then merge wifi support (possibly others) before ns-3.48 ships in May.

Edited by Tom Henderson

Merge request reports

Loading