xo-unit: restore constexpr quantity*quantity

This commit is contained in:
Roland Conybeare 2024-05-03 01:37:27 -04:00
commit be67f55c79
5 changed files with 66 additions and 35 deletions

View file

@ -230,7 +230,8 @@ namespace xo {
template <typename Repr = double,
typename Int = std::int64_t>
inline constexpr xquantity<Repr, Int>
unit_qty(const scaled_unit<Int> & u) {
unit_qty(const scaled_unit<Int> & u)
{
return xquantity<Repr, Int>
(u.outer_scale_factor_.template convert_to<double>() * ::sqrt(u.outer_scale_sq_),
u.natural_unit_);
@ -245,6 +246,18 @@ namespace xo {
return xquantity<Repr, Int>(1.0, nu);
}
/** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr)
**/
template <typename Q1, typename Q2>
requires (quantity_concept<Q1>
&& quantity_concept<Q2>
&& (!Q1::always_constexpr_unit || !Q2::always_constexpr_unit))
constexpr auto
operator* (const Q1 & x, const Q2 & y)
{
return Q1::multiply(x, y);
}
/** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr)
**/
template <typename Quantity, typename Quantity2>