General Information

unit-system is a C++-17 library to handle units in C++. The library is designed to be as easy to use as possible. It is split into four modules to allow custom unit systems that fit the need of everybody.

You can find the code on github. It already contains a wrap file in the repository, so that you can get started in a few seconds (as long as you use the meson build system). As of version 0.5.0 Arduino is supported, but this is not tested well and not on many boards. Feel free to open issues with your problems and pull requests with fixes or automated tests.

The modules


generic is the basis for the whole library. It contains the definition of the general unit type (sakurajin::unit_system::unit_t). unit_t is written as a template and can be used as a basis for any unit. In addition it contains definitions for the SI prefixes (eg. milli, mega, nano, …) and defines a unit_cast to change the multiplier and offset of a given value.

This library is still in an early stage so the documentation is lacking and a lot of units are missing. Pull requests are welcome.


base contains the base units of the SI unit system. All of these units are based on the unit_t, so it is not possible to use this module without the generic module. All of the units also have literals which allow easy creation of variable. It contains the following units:

  • time_si -> time with seconds as base unit
  • length -> length with meter as base unit
  • mass -> mass with kg as base unit
  • temperature -> temperature with K as base unit
  • amount -> amount of substance with mole as base unit
  • electric_current -> electric current with Ampere as base unit
  • luminous_intensity -> luminous intensity with candela as base unit

time_si also overloads the unit cast so that std::chrono::duration can be converted to sakurajin::unit_system::base::time_si. This overload is only done, when the compiler finds the <chrono> header. So it is NOT enabled on most arduino boards.

As of version 0.4.0 all of the base units are implemented and should work as expected.


common contains commonly used units based on the the base units. Like the base units the all have literals to make creating variables easy. The are the currently available units:

  • speed -> speed with m/s as base unit
  • acceleration -> acceleration with m/s² as base unit
  • momentum -> momentum with kg*m/s as base unit
  • force -> force with kg*m/s² (Newton) as base unit
  • energy -> energy with kg*m²/s² (Joules) as base unit
  • power -> power with kg*m²/s³ (Watts) as base unit

In the future there will be a lot more units, feel free to create new ones and open a pull request. A detailed page on how to create new units will come soon.


Extra will contain additional units that are not needed by most people because they are very domain specific. At the moment this module is empty.