From 7d7a424a9f02f180a6313d90143854773cde056f Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 7 May 2024 10:46:23 -0400 Subject: [PATCH] xo-unit: examples: + ex7 --- example/CMakeLists.txt | 1 + example/ex7/CMakeLists.txt | 14 ++++++++++++++ example/ex7/ex7.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 example/ex7/CMakeLists.txt create mode 100644 example/ex7/ex7.cpp diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 86f0d7e6..fc69f5c4 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(ex3) add_subdirectory(ex4) add_subdirectory(ex5) add_subdirectory(ex6) +add_subdirectory(ex7) diff --git a/example/ex7/CMakeLists.txt b/example/ex7/CMakeLists.txt new file mode 100644 index 00000000..33832b41 --- /dev/null +++ b/example/ex7/CMakeLists.txt @@ -0,0 +1,14 @@ +# xo-unit/example/ex7/CMakeLists.txt + +set(SELF_EXE xo_unit_ex7) +set(SELF_SRCS ex7.cpp) + +xo_add_executable(${SELF_EXE} ${SELF_SRCS}) + +# ---------------------------------------------------------------- +# dependencies.. + +xo_self_headeronly_dependency(${SELF_EXE} xo_unit) +xo_dependency(${SELF_EXE} xo_flatstring) + +# end CMakeLists.txt diff --git a/example/ex7/ex7.cpp b/example/ex7/ex7.cpp new file mode 100644 index 00000000..2339afa8 --- /dev/null +++ b/example/ex7/ex7.cpp @@ -0,0 +1,32 @@ +/** @file ex7.cpp **/ + +#include "xo/unit/quantity.hpp" +#include "xo/unit/quantity_iostream.hpp" +#include + +int +main () { + //namespace u = xo::unit::units; + using namespace xo::qty; + //namespace su = xo::qty::su; + namespace q = xo::qty::qty; + using namespace std; + + quantity qty1 = 7.55 * q::kilometer / q::minute / q::minute; + quantity qty2 = q::nanograms(123); + quantity qty3 = qty2 * qty1; + + cerr << "qty1: " << qty1 << endl; + cerr << "qty2: " << qty2 << endl; + cerr << "qty3: " << qty3 << endl; + + /* rescale to not-so-absurd units */ + + /* kg.m.s^-2 */ + quantity res = qty3.rescale_ext(); + + /* 2.57958e-10kg.m.s^-2 */ + cerr << "res: " << res << endl; +} + +/** end ex7.cpp */