From dd643109ccd48faa594a156fd39d9e281d7953a9 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 3 May 2024 18:45:37 -0400 Subject: [PATCH] xo-unit: streamlined ex2 --- example/ex2/CMakeLists.txt | 2 +- example/ex2/ex2.cpp | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/example/ex2/CMakeLists.txt b/example/ex2/CMakeLists.txt index 608daf93..339ba922 100644 --- a/example/ex2/CMakeLists.txt +++ b/example/ex2/CMakeLists.txt @@ -10,6 +10,6 @@ xo_include_options2(${SELF_EXE}) # dependencies.. xo_self_headeronly_dependency(${SELF_EXE} xo_unit) -#xo_dependency(${SELF_EXE} reflect) +xo_dependency(${SELF_EXE} xo_flatstring) # end CMakeLists.txt diff --git a/example/ex2/ex2.cpp b/example/ex2/ex2.cpp index 52b65a58..3fc1c94f 100644 --- a/example/ex2/ex2.cpp +++ b/example/ex2/ex2.cpp @@ -1,20 +1,41 @@ /** @file ex2.cpp **/ -#include "xo/unit/mpl/quantity.hpp" +#include "xo/unit/quantity.hpp" +#include "xo/unit/quantity_iostream.hpp" #include int main () { - namespace u = xo::unit::units; - namespace qty = xo::unit::qty; - using xo::unit::quantity; + namespace q = xo::qty::qty; + namespace su = xo::qty::su; + using xo::qty::with_units; + using xo::qty::quantity; + using xo::flatstring; using namespace std; - quantity t = qty::milliseconds(10); - quantity m = qty::kilograms(2.5); - auto a = m / (t*t); + constexpr auto t = q::minutes(2); + constexpr auto d = q::kilometers(2.5); - cerr << "t: " << t << ", m: " << m << ", m.t^-2: " << a << endl; + constexpr auto t2 = t*t; + constexpr auto a = d / (t*t); + + cerr << "t: " << t << ", d: " << d + << ", t^2: " << t2 + << ", d.t^-2: " << a + << endl; + + constexpr auto a2 = a.template rescale(); + + static_assert(a2.abbrev() == flatstring("m.s^-2")); + + cerr << "a2: " << a2 << endl; + + constexpr auto au = q::meter / (q::second * q::second); + constexpr auto a3 = with_units(a, au); + + static_assert(a3.abbrev() == flatstring("m.s^-2")); + + cerr << "a3: " << a3 << endl; } /** end ex2.cpp **/