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
dimensionstruct 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, andenergyare provided. -
User-defined literals — write
1_m,3.5_kg,90_deg,1_sand more vianin::literals. -
Physical constants — speed of light, Planck constant, and others in
nin::constants. -
Math overloads —
sqrt,hypot,asin,acos,atan,atan2with dimension-aware return types. -
Formatting —
std::formatterspecialisations 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
-
Overview — framework introduction
-
dimension — SI dimensional exponents
-
quantity<D,T> — dimensional quantities with operators
-
Literals, Factories & Aliases — literal operators and factory functions
-
Physical Constants — mathematical and physical constants