What It Is

A zero-dependency C++23 library that wraps primitives in named types so the compiler catches unit and coordinate mix-ups before your code ever runs.

auto altitude = 500.0_m;
auto speed = 120.0_kmh;
// altitude + speed;  // compile error -- incompatible dimensions

Why It Exists

Because meters and feet should never silently convert. In drone avionics, mixing up coordinate frames or physical units isn’t a bug report – it’s a crash. This library makes those mistakes impossible at the type level.

Key Features

  • constexpr everything – compile-time math where supported
  • SI units with trait-based dimensional analysis (length, mass, time, speed, force, energy, etc.)
  • Scaled unitsKilometers, Milliseconds, KilometersPerHour with compile-time ratio conversions
  • User-defined literals5.0_m, 9.81_mps2, 100.0_km, 36.0_kmh
  • Quantity points (affine types) – type-safe absolute positions (MSL altitude, GPS coordinates)
  • Safe integer mathstd::expected-based overflow/underflow/division-by-zero detection
  • Non-arithmetic TStrong<Vec2, PositionTag> works with vectors, quaternions, custom types
  • ~1,500 LOC – minimal compile-time overhead

How It Compares

Featurestrong-typesmp-unitsAunholthaus/units
C++ standardC++23C++20C++14C++14
Header-onlyyesnoyesyes
Dependencieszerogsl-litenonenone
LOC~1,500~30,000~15,000~12,000
Custom non-arithmetic Tyesnonono
Integer overflow safetyyespartialbest-in-classno

Installation

include(FetchContent)
FetchContent_Declare(strong-types
    GIT_REPOSITORY https://github.com/PavelGuzenfeld/strong-types.git
    GIT_TAG v0.2.10)
FetchContent_MakeAvailable(strong-types)
target_link_libraries(your_target PRIVATE strong-types)

View on GitHub