xo-unit ++ docs ++ quantity arithmetic + example

This commit is contained in:
Roland Conybeare 2024-05-23 14:44:00 -04:00
commit b0ce5eaee9
34 changed files with 713 additions and 173 deletions

View file

@ -7,3 +7,4 @@ add_subdirectory(ex6)
add_subdirectory(ex7)
add_subdirectory(ex8)
add_subdirectory(ex_su)
add_subdirectory(ex_qty)

View file

@ -8,11 +8,12 @@ int
main () {
using namespace xo::qty;
namespace u = xo::qty::u;
//namespace q = xo::qty::qty;
using namespace std;
xquantity qty1(7, u::foot);
xquantity qty2(6.0, u::inch);
constexpr xquantity qty1(7, u::foot);
constexpr xquantity qty2(6.0, u::inch);
// constexpr not supported for xquantity addition
xquantity qty3 = qty1 + qty2;
cerr << "qty1: " << qty1 << endl;
@ -24,6 +25,13 @@ main () {
/* 2286mm */
cerr << "res: " << res << endl;
/* 12 */
xquantity qty4 = qty1 / qty2;
auto res2 = qty4 + 4;
cerr << "res2: " << res << endl;
}
/** end ex8.cpp */

View file

@ -0,0 +1,12 @@
# xo-unit/example/ex_qty/CMakeLists.txt
set(SELF_EXE xo_unit_ex_qty)
set(SELF_SRCS ex_qty.cpp)
if (XO_ENABLE_EXAMPLES)
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
xo_dependency(${SELF_EXE} xo_flatstring)
endif()
# end CMakeLists.txt

18
example/ex_qty/ex_qty.cpp Normal file
View file

@ -0,0 +1,18 @@
/* @file ex_qty.cpp */
#include "xo/unit/quantity.hpp"
#include "xo/unit/quantity_iostream.hpp"
using namespace std;
int
main() {
using namespace xo::qty;
namespace u = xo::qty::u;
static_assert(u::meter.n_bpu() == 1);
//constexpr auto q = qty::meters(2) + u::meter;
}
/* end ex_qty.cpp */