![]() |
qtty-cpp
Header-only C++ wrapper for qtty
|
qtty-cpp is a modern, header-only C++17 library for working with physical quantities using strongly-typed, unit-safe value types. It wraps the Rust-based qtty conversion engine through its C FFI layer (qtty-ffi), giving you compile-time dimension safety and zero-overhead unit conversions without writing a single line of Rust.
| Feature | Description |
|---|---|
| Strong unit types | Each unit (e.g., Meter, Second, Kilogram) is a distinct C++ type — mixing incompatible dimensions is a compile error |
| Unit conversion | Quantity::to<T>() delegates to the qtty-ffi Rust engine for exact conversions |
| User-defined literals | Ergonomic construction: 10.0_km, 5.0_s, 90.0_deg, 1.0_kg |
| Generated headers | Unit aliases and literals auto-generated from qtty_ffi.h — always in sync with the Rust layer |
| CMake integration | One target_link_libraries call: qtty_cpp |
qtty/qtty.hpp — umbrella include for the full public APIqtty/ffi_core.hpp — FFI helpers and exception hierarchyqtty/units/length.hpp — Meter, Kilometer, Mile, NauticalMile, …qtty/units/time.hpp — Second, Minute, Hour, Day, …qtty/units/angular.hpp — Radian, Degree, ArcMinute, ArcSecond, …qtty/units/mass.hpp — Kilogram, Gram, Pound, …qtty/units/velocity.hpp — compound velocity typesqtty/literals.hpp — user-defined literals for all unitsqtty/serialization.hpp — optional JSON/serde helpersFFI status codes are translated into typed C++ exceptions:
| Exception | When thrown |
|---|---|
QttyException | Base class for all qtty errors |
InvalidUnitError | Unrecognised unit identifier |
IncompatibleDimensionsError | Conversion between incompatible dimensions |
ConversionError | Numeric conversion failure in the FFI layer |
cargo) — qtty-ffi is built automaticallyThen open:
build/docs/doxygen/html/index.html