Units Library

The Units library (ninbot.units) provides compile-time dimensional analysis with physical units based on the International System of Units (SI).

Getting Started

import ninbot.units;

int main()
{
    using namespace nin::literals;

    nin::length distance = 10_m;
    nin::time   duration = 2_s;
    nin::speed  velocity = distance / duration;

    std::println("Velocity: {}", velocity);
    return 0;
}

Key Features

  • Dimensional analysis — dimensions are tracked at compile time via the dimension struct encoding the 7 SI base dimensions.

  • Quantities — the quantity<D, T> class template is parameterised on a dimension and a numeric type.

  • Type aliases — common quantities such as length, angle, speed, force, and energy are provided.

  • User-defined literals — write 1_m, 3.5_kg, 90_deg, 1_s and more via nin::literals.

  • Physical constants — speed of light, Planck constant, and others in nin::constants.

  • Math overloads — sqrt, hypot, asin, acos, atan, atan2 with dimension-aware return types.

  • Formatting — std::formatter specialisations for unit-aware output with pretty exponents.

Namespaces

nin::inline units

Core types and aliases (accessible as nin::length, nin::angle, etc.).

nin::literals

User-defined literal operators.

nin::constants

Physical constants.

Reference