xo-unit: + with_units + example
This commit is contained in:
parent
4ee89948d9
commit
779e7e0569
2 changed files with 17 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ main () {
|
|||
namespace q = xo::qty::qty;
|
||||
namespace su = xo::qty::su;
|
||||
using xo::qty::with_units_from;
|
||||
using xo::qty::with_units;
|
||||
using xo::qty::quantity;
|
||||
using xo::flatstring;
|
||||
using namespace std;
|
||||
|
|
@ -30,12 +31,18 @@ main () {
|
|||
|
||||
cerr << "a2: " << a2 << endl;
|
||||
|
||||
constexpr auto au = q::meter / (q::second * q::second);
|
||||
constexpr auto a3 = with_units_from(a, au);
|
||||
constexpr auto a3 = with_units<su::meter / (su::second * su::second)>(a);
|
||||
|
||||
static_assert(a3.abbrev() == flatstring("m.s^-2"));
|
||||
|
||||
cerr << "a3: " << a3 << endl;
|
||||
|
||||
constexpr auto au = q::meter / (q::second * q::second);
|
||||
constexpr auto a4 = with_units_from(a, au);
|
||||
|
||||
static_assert(a4.abbrev() == flatstring("m.s^-2"));
|
||||
|
||||
cerr << "a4: " << a4 << endl;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -227,6 +227,14 @@ namespace xo {
|
|||
};
|
||||
} /*namespace detail*/
|
||||
|
||||
template <auto Unit, typename Q1>
|
||||
requires(quantity_concept<Q1>
|
||||
&& Q1::always_constexpr_unit)
|
||||
constexpr auto
|
||||
with_units(const Q1 & x) {
|
||||
return x.template rescale_ext<Unit>();
|
||||
}
|
||||
|
||||
template <typename Q1, typename Q2, auto Unit = Q2::s_unit>
|
||||
requires (quantity_concept<Q1>
|
||||
&& quantity_concept<Q2>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue