From ba31d2c1122ab9f4ab242497269f3134160f354f Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 3 Apr 2024 17:25:20 -0400 Subject: [PATCH] xo-unit: example: + ex4 .. ex6 --- example/CMakeLists.txt | 3 +++ example/ex4/CMakeLists.txt | 15 +++++++++++++++ example/ex4/ex4.cpp | 26 ++++++++++++++++++++++++++ example/ex5/CMakeLists.txt | 15 +++++++++++++++ example/ex5/ex5.cpp | 23 +++++++++++++++++++++++ example/ex6/CMakeLists.txt | 15 +++++++++++++++ example/ex6/ex6.cpp | 19 +++++++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 example/ex4/CMakeLists.txt create mode 100644 example/ex4/ex4.cpp create mode 100644 example/ex5/CMakeLists.txt create mode 100644 example/ex5/ex5.cpp create mode 100644 example/ex6/CMakeLists.txt create mode 100644 example/ex6/ex6.cpp diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ed03faf2..86f0d7e6 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,3 +1,6 @@ add_subdirectory(ex1) add_subdirectory(ex2) add_subdirectory(ex3) +add_subdirectory(ex4) +add_subdirectory(ex5) +add_subdirectory(ex6) diff --git a/example/ex4/CMakeLists.txt b/example/ex4/CMakeLists.txt new file mode 100644 index 00000000..5e88f779 --- /dev/null +++ b/example/ex4/CMakeLists.txt @@ -0,0 +1,15 @@ +# xo-unit/example/ex4/CMakeLists.txt + +set(SELF_EXE xo_unit_ex4) +set(SELF_SRCS ex4.cpp) + +add_executable(${SELF_EXE} ${SELF_SRCS}) +xo_include_options2(${SELF_EXE}) + +# ---------------------------------------------------------------- +# dependencies.. + +xo_self_dependency(${SELF_EXE} xo_unit) +xo_dependency(${SELF_EXE} reflect) + +# end CMakeLists.txt diff --git a/example/ex4/ex4.cpp b/example/ex4/ex4.cpp new file mode 100644 index 00000000..6db7f145 --- /dev/null +++ b/example/ex4/ex4.cpp @@ -0,0 +1,26 @@ +/** @file ex4.cpp **/ + +#include "xo/unit/quantity.hpp" +#include + +int +main () { + namespace u = xo::unit::units; + namespace qty = xo::unit::qty; + using namespace std; + + /* 20% volatility over 250 days (approx number of trading days in one year) */ + auto t1 = qty::milliseconds(1); + /* 10% volatility over 30 days */ + auto t2 = qty::minutes(1); + + auto r1 = t1 / t2.with_repr(); + auto r2 = t2 / t1.with_repr(); + + static_assert(same_as); + static_assert(same_as); + + cerr << "t1: " << t1 << ", t2: " << t2 << ", t1/t2: " << r1 << ", t2/t1: " << r2 << endl; +} + +/** end ex4.cpp */ diff --git a/example/ex5/CMakeLists.txt b/example/ex5/CMakeLists.txt new file mode 100644 index 00000000..583a7cff --- /dev/null +++ b/example/ex5/CMakeLists.txt @@ -0,0 +1,15 @@ +# xo-unit/example/ex5/CMakeLists.txt + +set(SELF_EXE xo_unit_ex5) +set(SELF_SRCS ex5.cpp) + +add_executable(${SELF_EXE} ${SELF_SRCS}) +xo_include_options2(${SELF_EXE}) + +# ---------------------------------------------------------------- +# dependencies.. + +xo_self_dependency(${SELF_EXE} xo_unit) +xo_dependency(${SELF_EXE} reflect) + +# end CMakeLists.txt diff --git a/example/ex5/ex5.cpp b/example/ex5/ex5.cpp new file mode 100644 index 00000000..2f0dbb9e --- /dev/null +++ b/example/ex5/ex5.cpp @@ -0,0 +1,23 @@ +/** @file ex5.cpp **/ + +#include "xo/unit/quantity.hpp" +#include + +int +main () { + namespace u = xo::unit::units; + namespace qty = xo::unit::qty; + using namespace std; + + /* 20% volatility over 250 days (approx number of trading days in one year) */ + auto q1 = qty::volatility250d(0.2); + /* 10% volatility over 30 days */ + auto q2 = qty::volatility30d(0.1); + + auto sum = q1 + q2; + auto prod = q1 * q2; + + cerr << "q1: " << q1 << ", q2: " << q2 << ", q1+q2: " << sum << ", q1*q2: " << prod << endl; +} + +/** end ex5.cpp */ diff --git a/example/ex6/CMakeLists.txt b/example/ex6/CMakeLists.txt new file mode 100644 index 00000000..cff85d53 --- /dev/null +++ b/example/ex6/CMakeLists.txt @@ -0,0 +1,15 @@ +# xo-unit/example/ex6/CMakeLists.txt + +set(SELF_EXE xo_unit_ex6) +set(SELF_SRCS ex6.cpp) + +add_executable(${SELF_EXE} ${SELF_SRCS}) +xo_include_options2(${SELF_EXE}) + +# ---------------------------------------------------------------- +# dependencies.. + +xo_self_dependency(${SELF_EXE} xo_unit) +xo_dependency(${SELF_EXE} reflect) + +# end CMakeLists.txt diff --git a/example/ex6/ex6.cpp b/example/ex6/ex6.cpp new file mode 100644 index 00000000..9046f331 --- /dev/null +++ b/example/ex6/ex6.cpp @@ -0,0 +1,19 @@ +/** @file ex6.cpp **/ + +#include "xo/unit/quantity.hpp" +#include + +int +main () { + namespace u = xo::unit::units; + namespace qty = xo::unit::qty; + using namespace std; + + auto t1 = qty::milliseconds(25.0); + auto t1_usec = t1.with_unit(); + auto t1_sec = t1.with_unit(); + + cerr << "t1: " << t1 << ", t1_usec: " << t1_usec << ", t1_sec: " << t1_sec << endl; +} + +/** end ex6.cpp */