xo-unit: kitchen-sink doc + build improvements + 1 bug fix
This commit is contained in:
parent
0664af34c5
commit
412a0ba163
45 changed files with 1712 additions and 472 deletions
|
|
@ -5,3 +5,5 @@ add_subdirectory(ex4)
|
|||
add_subdirectory(ex5)
|
||||
add_subdirectory(ex6)
|
||||
add_subdirectory(ex7)
|
||||
add_subdirectory(ex8)
|
||||
add_subdirectory(ex_su)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
set(SELF_EXE xo_unit_ex1)
|
||||
set(SELF_SRCS ex1.cpp)
|
||||
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} xo_flatstring)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
set(SELF_EXE xo_unit_ex2)
|
||||
set(SELF_SRCS ex2.cpp)
|
||||
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} xo_flatstring)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
set(SELF_EXE xo_unit_ex3)
|
||||
set(SELF_SRCS ex3.cpp)
|
||||
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} xo_flatstring)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ int
|
|||
main () {
|
||||
namespace q = xo::qty::qty;
|
||||
namespace u = xo::qty::u;
|
||||
//namespace nu = xo::qty::nu;
|
||||
using xo::qty::quantity;
|
||||
using xo::flatstring;
|
||||
using namespace std;
|
||||
|
||||
constexpr quantity<u::second> t = q::minutes(2);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
set(SELF_EXE xo_unit_ex4)
|
||||
set(SELF_SRCS ex4.cpp)
|
||||
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} xo_flatstring)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ main () {
|
|||
static_assert(!t2.is_dimensionless());
|
||||
|
||||
static_assert(std::same_as<decltype(static_cast<double>(r1)), double>);
|
||||
//static_assert(std::same_as<decltype(static_cast<double>(t2)), double>);
|
||||
|
||||
/* r1_value: assignment compiles, since r1 dimensionless */
|
||||
double r1_value = r1;
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
set(SELF_EXE xo_unit_ex5)
|
||||
set(SELF_SRCS ex5.cpp)
|
||||
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} xo_flatstring)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
set(SELF_EXE xo_unit_ex6)
|
||||
set(SELF_SRCS ex6.cpp)
|
||||
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_headeronly_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} xo_flatstring)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
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)
|
||||
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
|
||||
|
|
|
|||
12
example/ex8/CMakeLists.txt
Normal file
12
example/ex8/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# xo-unit/example/ex8/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_unit_ex8)
|
||||
set(SELF_SRCS ex8.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
|
||||
29
example/ex8/ex8.cpp
Normal file
29
example/ex8/ex8.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/** @file ex8.cpp **/
|
||||
|
||||
#include "xo/unit/xquantity.hpp"
|
||||
#include "xo/unit/xquantity_iostream.hpp"
|
||||
#include <iostream>
|
||||
|
||||
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);
|
||||
xquantity qty3 = qty1 + qty2;
|
||||
|
||||
cerr << "qty1: " << qty1 << endl;
|
||||
cerr << "qty2: " << qty2 << endl;
|
||||
cerr << "qty3: " << qty3 << endl;
|
||||
|
||||
/* rescale to mm */
|
||||
xquantity res = qty3.rescale(xo::qty::nu::millimeter);
|
||||
|
||||
/* 2286mm */
|
||||
cerr << "res: " << res << endl;
|
||||
}
|
||||
|
||||
/** end ex8.cpp */
|
||||
12
example/ex_su/CMakeLists.txt
Normal file
12
example/ex_su/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# xo-unit/example/su/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_unit_ex_su)
|
||||
set(SELF_SRCS ex_su.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
|
||||
38
example/ex_su/ex_su.cpp
Normal file
38
example/ex_su/ex_su.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/** @file ex_su.cpp **/
|
||||
|
||||
#include "xo/unit/scaled_unit.hpp"
|
||||
#include "xo/unit/scaled_unit_iostream.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main() {
|
||||
using namespace xo::qty;
|
||||
|
||||
constexpr auto u_prod = u::meter * u::kilometer;
|
||||
|
||||
static_assert(u_prod[0].bu() == detail::bu::meter);
|
||||
static_assert(u_prod[0].power() == power_ratio_type(2));
|
||||
static_assert(u_prod.outer_scale_factor_ == xo::ratio::ratio<int64_t>(1000));
|
||||
static_assert(u_prod.outer_scale_sq_ == 1.0); // used if fractional dimension
|
||||
|
||||
constexpr auto u_div = u::meter / u::kilometer;
|
||||
|
||||
static_assert(u_div.n_bpu() == 0);
|
||||
static_assert(u_div.outer_scale_factor_ == xo::ratio::ratio<int64_t>(1,1000));
|
||||
static_assert(u_prod.outer_scale_sq_ == 1.0); // used if fractional dimension
|
||||
|
||||
constexpr auto u2_prod = u::meter * u::hour * u::kilometer * u::minute;
|
||||
|
||||
static_assert(u2_prod.n_bpu() == 2);
|
||||
static_assert(u2_prod[0].bu() == detail::bu::meter);
|
||||
static_assert(u2_prod[1].bu() == detail::bu::hour);
|
||||
// *1000 from converting kilometers -> meters
|
||||
// /60 from converting minutes -> hours
|
||||
// 1000/60 = 50/3 in lowest terms
|
||||
static_assert(u2_prod.outer_scale_factor_ == xo::ratio::ratio<int64_t>(50,3)); // used if fractional dimension
|
||||
static_assert(u2_prod.outer_scale_sq_ == 1.0); // used if fractional dimension
|
||||
}
|
||||
|
||||
/** end ex_su.cpp **/
|
||||
Loading…
Add table
Add a link
Reference in a new issue