Skip to content

Welcome to mp-units!

mp-units is the only Modern C++ (C++20) library providing the full spectrum of compile‑time safety for physical quantities and units — from dimensional analysis and unit conversions to quantity kind safety — built on the ISO 80000 International System of Quantities (ISQ).

The library source code is hosted on GitHub with a permissive MIT license.

#include <iostream>
#include <print>
import mp_units;

using namespace mp_units;

inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot;

int main()
{
  constexpr quantity dist = 364.4 * smoot;
  std::println("Harvard Bridge length = {::N[.1f]} ({::N[.1f]}, {::N[.2f]}) ± 1 εar",
               dist, dist.in(usc::foot), dist.in(si::metre));
}
#include <mp-units/systems/si.h>
#include <mp-units/systems/usc.h>
#include <print>

using namespace mp_units;

inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot;

int main()
{
  constexpr quantity dist = 364.4 * smoot;
  std::println("Harvard Bridge length = {::N[.1f]} ({::N[.1f]}, {::N[.2f]}) ± 1 εar",
               dist, dist.in(usc::foot), dist.in(si::metre));
}

Output:

Harvard Bridge length = 364.4 smoot (2034.6 ft, 620.14 m) ± 1 εar

Try it live on Compiler Explorer

What is smoot?

The smoot (/ˈsmuːt/) is a nonstandard unit of length created as part of an MIT fraternity prank. It is named after Oliver R. Smoot, a fraternity pledge to Lambda Chi Alpha, who, in October 1958, lay on the Harvard Bridge (between Boston and Cambridge, Massachusetts) and was used by his fraternity brothers to measure the length of the bridge.

One smoot equals Oliver Smoot's height at the time of the prank (five feet and seven inches). The bridge's length was measured to be 364.4 smoots plus or minus one ear, with the "plus or minus" intended to express the measurement uncertainty.

Oliver Smoot graduated from MIT with the class of 1962, became a lawyer, and later became chairman of the American National Standards Institute (ANSI) and president of the International Organization for Standardization (ISO).

More on the smoot unit of length can be found at https://en.wikipedia.org/wiki/Smoot.

Supported compilers

This library tries to provide the best user experience possible with the C++ language. To achieve that, it extensively uses the latest C++ language features.

Even though the library benefits from the latest C++ versions (if available), C++20 is enough to compile and use all of the library's functionality.

Please refer to C++ compiler support chapter for more details.

Help shape the future of C++!

mp-units is a candidate for ISO standardization in C++29. To support this effort, we need your help in demonstrating its real-world value to the ISO C++ Committee.

We are seeking:

  • Field trial partners – Organizations interested in evaluating the library in production environments
  • Success stories – Real-world testimonials from production deployments, research projects, or educational use
  • Feedback – Practical insights from developers, academics, and organizations using the library

Your experience—whether from production systems, research applications, or teaching—provides invaluable evidence for standardization and helps other potential users evaluate the library.

Share Your Experience

For more details, see the ISO C++ proposals: P1935 · P2980 · P3045 · P4185

Learn it from the author

The Tutorials, Workshops, and How-to Guides are written for self-study and cover the whole library.

These pages tell you how. For the why, have it taught: a two-day workshop covering the reasoning behind the design decisions, the trade-offs each one resolves, and the modeling questions that only come up once a real codebase is involved. It goes further than the documentation does, and the exercises are re-skinned into the vocabulary of your team's domain, so your engineers practise on quantities they recognise rather than on textbook examples.

What those domains turn out to need feeds back into the library and the standardization proposal, which is the same evidence the field trials above ask for.

Domain Modeling with the C++ Type System