From 8f7d60dd21395de0e877534e59a9160e3fde6c89 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 3 May 2024 01:38:21 -0400 Subject: [PATCH] xo-unit: ex1: upgrade to qty::quantity<..> with constexpr units --- example/ex1/CMakeLists.txt | 1 + example/ex1/ex1.cpp | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/example/ex1/CMakeLists.txt b/example/ex1/CMakeLists.txt index 63c0c8a0..37ce3f44 100644 --- a/example/ex1/CMakeLists.txt +++ b/example/ex1/CMakeLists.txt @@ -10,6 +10,7 @@ xo_include_options2(${SELF_EXE}) # dependencies.. xo_self_headeronly_dependency(${SELF_EXE} xo_unit) +xo_dependency(${SELF_EXE} xo_flatstring) #xo_dependency(${SELF_EXE} reflect) # end CMakeLists.txt diff --git a/example/ex1/ex1.cpp b/example/ex1/ex1.cpp index 27de59ab..d8cd61c5 100644 --- a/example/ex1/ex1.cpp +++ b/example/ex1/ex1.cpp @@ -1,22 +1,29 @@ /** @file ex1.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; + using xo::qty::quantity; using namespace std; - auto t = qty::milliseconds(10); - auto m = qty::kilograms(2.5); - auto a = m / (t*t); + constexpr auto t = q::milliseconds(10); + constexpr auto m = q::kilograms(2.5); + + constexpr auto t2 = t*t; +#ifdef NOT_YET + constexpr auto a = m / (t*t); static_assert(same_as>); +#endif - cerr << "t: " << t << ", m: " << m << ", m.t^-2: " << a << endl; + cerr << "t: " << t << ", m: " << m + << ", t^2: " << t2 + //<< ", m.t^-2: " << a + << endl; } /** end ex1.cpp **/