diff --git a/example/currency.cpp b/example/currency.cpp index ae3267663..40892ad2a 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -82,7 +82,7 @@ template auto To, ReferenceOf auto From, auto PO quantity_point exchange_to(quantity_point q) { return quantity_point{zero + static_cast(exchange_rate() * - (q - q.absolute_point_origin).numerical_value_ref_in(q.unit)) * + (q - q.absolute_point_origin).numerical_value_in(q.unit)) * To}; } diff --git a/src/core-fmt/include/mp-units/format.h b/src/core-fmt/include/mp-units/format.h index 510584d90..7929bb2f7 100644 --- a/src/core-fmt/include/mp-units/format.h +++ b/src/core-fmt/include/mp-units/format.h @@ -224,9 +224,9 @@ struct quantity_formatter { const quantity_format_specs& specs; Locale loc; - explicit quantity_formatter(OutputIt o, quantity q, const quantity_format_specs& fspecs, + explicit quantity_formatter(OutputIt o, const quantity& q, const quantity_format_specs& fspecs, Locale lc) : - out(o), val(std::move(q).numerical_value_ref_in(q.unit)), specs(fspecs), loc(std::move(lc)) + out(o), val(q.numerical_value_ref_in(q.unit)), specs(fspecs), loc(std::move(lc)) { } diff --git a/src/core/include/mp-units/bits/quantity_cast.h b/src/core/include/mp-units/bits/quantity_cast.h index fe88b85a5..4fa7d08b9 100644 --- a/src/core/include/mp-units/bits/quantity_cast.h +++ b/src/core/include/mp-units/bits/quantity_cast.h @@ -51,9 +51,9 @@ template { if constexpr (detail::QuantityKindSpec> && AssociatedUnit>) - return make_quantity(std::forward(q).numerical_value_ref_in(q.unit)); + return make_quantity(std::forward(q).numerical_value_); else - return make_quantity{}>(std::forward(q).numerical_value_ref_in(q.unit)); + return make_quantity{}>(std::forward(q).numerical_value_); } } // namespace mp_units diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index 75b53dc9e..49f6dc52e 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -63,10 +63,10 @@ template if constexpr (q_unit == To::unit) { // no scaling of the number needed return make_quantity(static_cast( - std::forward(q).numerical_value_ref_in(q_unit))); // this is the only (and recommended) way to do - // a truncating conversion on a number, so we are - // using static_cast to suppress all the compiler - // warnings on conversions + std::forward(q).numerical_value_)); // this is the only (and recommended) way to do + // a truncating conversion on a number, so we are + // using static_cast to suppress all the compiler + // warnings on conversions } else { // scale the number constexpr Magnitude auto c_mag = get_canonical_unit(q_unit).mag / get_canonical_unit(To::unit).mag; @@ -78,9 +78,8 @@ template using multiplier_type = conditional, std::common_type_t, c_mag_type>; constexpr auto val = [](Magnitude auto m) { return get_value(m); }; - return static_cast( - static_cast(std::forward(q).numerical_value_ref_in(q_unit)) * val(num) / val(den) * - val(irr)) * + return static_cast(static_cast(std::forward(q).numerical_value_) * + val(num) / val(den) * val(irr)) * To::reference; } } diff --git a/src/core/include/mp-units/quantity.h b/src/core/include/mp-units/quantity.h index 6c3f9f1b8..2e9fab497 100644 --- a/src/core/include/mp-units/quantity.h +++ b/src/core/include/mp-units/quantity.h @@ -126,7 +126,7 @@ class quantity { template Q> constexpr explicit(!std::convertible_to) quantity(const Q& q) : - numerical_value_(detail::sudo_cast(q).numerical_value_ref_in(unit)) + numerical_value_(detail::sudo_cast(q).numerical_value_) { } @@ -157,52 +157,36 @@ class quantity { } // data access -#ifdef __cpp_explicit_this_parameter - template - requires(U{} == unit) - [[nodiscard]] constexpr auto&& numerical_value_ref_in(this Self&& self, U) noexcept - { - return std::forward(self).numerical_value_; - } -#else template requires(U{} == unit) [[nodiscard]] constexpr rep& numerical_value_ref_in(U) & noexcept { return numerical_value_; } + template requires(U{} == unit) [[nodiscard]] constexpr const rep& numerical_value_ref_in(U) const& noexcept { return numerical_value_; } + template requires(U{} == unit) - [[nodiscard]] constexpr rep&& numerical_value_ref_in(U) && noexcept - { - return std::move(numerical_value_); - } - template - requires(U{} == unit) - [[nodiscard]] constexpr const rep&& numerical_value_ref_in(U) const&& noexcept - { - return std::move(numerical_value_); - } -#endif + constexpr const rep&& numerical_value_ref_in(U) const&& noexcept = delete; template requires requires(quantity q) { q.in(U{}); } [[nodiscard]] constexpr rep numerical_value_in(U) const noexcept { - return (*this).in(U{}).numerical_value_ref_in(U{}); + return (*this).in(U{}).numerical_value_; } template requires requires(quantity q) { q.force_in(U{}); } [[nodiscard]] constexpr rep force_numerical_value_in(U) const noexcept { - return (*this).force_in(U{}).numerical_value_ref_in(U{}); + return (*this).force_in(U{}).numerical_value_; } // member unary operators @@ -213,7 +197,7 @@ class quantity { } -> std::common_with; } { - return make_quantity(+numerical_value_ref_in(unit)); + return make_quantity(+numerical_value_); } [[nodiscard]] constexpr Quantity auto operator-() const @@ -223,7 +207,7 @@ class quantity { } -> std::common_with; } { - return make_quantity(-numerical_value_ref_in(unit)); + return make_quantity(-numerical_value_); } constexpr quantity& operator++() @@ -387,8 +371,7 @@ template [[nodiscard]] constexpr Quantity auto operator+(const quantity& lhs, const quantity& rhs) { using ret = detail::common_quantity_for, quantity, quantity>; - return make_quantity(ret(lhs).numerical_value_ref_in(ret::unit) + - ret(rhs).numerical_value_ref_in(ret::unit)); + return make_quantity(ret(lhs).numerical_value_ + ret(rhs).numerical_value_); } template @@ -396,8 +379,7 @@ template [[nodiscard]] constexpr Quantity auto operator-(const quantity& lhs, const quantity& rhs) { using ret = detail::common_quantity_for, quantity, quantity>; - return make_quantity(ret(lhs).numerical_value_ref_in(ret::unit) - - ret(rhs).numerical_value_ref_in(ret::unit)); + return make_quantity(ret(lhs).numerical_value_ - ret(rhs).numerical_value_); } template @@ -407,8 +389,7 @@ template { gsl_ExpectsAudit(rhs != rhs.zero()); using ret = detail::common_quantity_for, quantity, quantity>; - return make_quantity(ret(lhs).numerical_value_ref_in(ret::unit) % - ret(rhs).numerical_value_ref_in(ret::unit)); + return make_quantity(ret(lhs).numerical_value_ % ret(rhs).numerical_value_); } template @@ -416,7 +397,7 @@ template Rep2> [[nodiscard]] constexpr Quantity auto operator*(const quantity& lhs, const quantity& rhs) { - return make_quantity(lhs.numerical_value_ref_in(get_unit(R1)) * rhs.numerical_value_ref_in(get_unit(R2))); + return make_quantity(lhs.numerical_value_ * rhs.numerical_value_); } template @@ -424,7 +405,7 @@ template detail::InvokeResultOf, Rep, const Value&> [[nodiscard]] constexpr Quantity auto operator*(const quantity& q, const Value& v) { - return make_quantity(q.numerical_value_ref_in(get_unit(R)) * v); + return make_quantity(q.numerical_value_ * v); } template @@ -432,7 +413,7 @@ template detail::InvokeResultOf, const Value&, Rep> [[nodiscard]] constexpr Quantity auto operator*(const Value& v, const quantity& q) { - return make_quantity(v * q.numerical_value_ref_in(get_unit(R))); + return make_quantity(v * q.numerical_value_); } template @@ -440,7 +421,7 @@ template [[nodiscard]] constexpr Quantity auto operator/(const quantity& lhs, const quantity& rhs) { gsl_ExpectsAudit(rhs != rhs.zero()); - return make_quantity(lhs.numerical_value_ref_in(get_unit(R1)) / rhs.numerical_value_ref_in(get_unit(R2))); + return make_quantity(lhs.numerical_value_ / rhs.numerical_value_); } template @@ -449,7 +430,7 @@ template [[nodiscard]] constexpr Quantity auto operator/(const quantity& q, const Value& v) { gsl_ExpectsAudit(v != quantity_values::zero()); - return make_quantity(q.numerical_value_ref_in(get_unit(R)) / v); + return make_quantity(q.numerical_value_ / v); } template @@ -457,7 +438,7 @@ template detail::InvokeResultOf, const Value&, Rep> [[nodiscard]] constexpr Quantity auto operator/(const Value& v, const quantity& q) { - return make_quantity<::mp_units::one / R>(v / q.numerical_value_ref_in(get_unit(R))); + return make_quantity<::mp_units::one / R>(v / q.numerical_value_); } template @@ -466,7 +447,7 @@ template [[nodiscard]] constexpr bool operator==(const quantity& lhs, const quantity& rhs) { using ct = std::common_type_t, quantity>; - return ct(lhs).numerical_value_ref_in(ct::unit) == ct(rhs).numerical_value_ref_in(ct::unit); + return ct(lhs).numerical_value_ == ct(rhs).numerical_value_; } template @@ -475,7 +456,7 @@ template [[nodiscard]] constexpr auto operator<=>(const quantity& lhs, const quantity& rhs) { using ct = std::common_type_t, quantity>; - return ct(lhs).numerical_value_ref_in(ct::unit) <=> ct(rhs).numerical_value_ref_in(ct::unit); + return ct(lhs).numerical_value_ <=> ct(rhs).numerical_value_; } // make_quantity diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index b55adf620..b6e2e2a1a 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -111,8 +111,7 @@ struct quantity_spec_interface { requires Quantity> && (explicitly_convertible(std::remove_reference_t::quantity_spec, self)) { - return make_quantity::unit>{}>( - std::forward(q).numerical_value_ref_in(q.unit)); + return make_quantity::unit>{}>(std::forward(q).numerical_value_); } #else template U> @@ -129,8 +128,7 @@ struct quantity_spec_interface { (explicitly_convertible(std::remove_reference_t::quantity_spec, Self_{})) [[nodiscard]] constexpr Quantity auto operator()(Q&& q) const { - return make_quantity::unit>{}>( - std::forward(q).numerical_value_ref_in(q.unit)); + return make_quantity::unit>{}>(std::forward(q).numerical_value_); } #endif }; @@ -309,8 +307,7 @@ struct quantity_spec : std::remove_const_t { (explicitly_convertible(std::remove_reference_t::quantity_spec, Self_{})) [[nodiscard]] constexpr Quantity auto operator()(Q&& q) const { - return make_quantity::unit>{}>( - std::forward(q).numerical_value_ref_in(q.unit)); + return make_quantity::unit>{}>(std::forward(q).numerical_value_); } #endif }; diff --git a/test/unit_test/runtime/almost_equals.h b/test/unit_test/runtime/almost_equals.h index 038dfb6e5..b3af6689b 100644 --- a/test/unit_test/runtime/almost_equals.h +++ b/test/unit_test/runtime/almost_equals.h @@ -36,8 +36,8 @@ struct AlmostEqualsMatcher : Catch::Matchers::MatcherGenericBase { { using std::abs; using common = std::common_type_t; - const auto x = common(target_).numerical_value_ref_in(common::unit); - const auto y = common(other).numerical_value_ref_in(common::unit); + const auto x = common(target_).numerical_value_in(common::unit); + const auto y = common(other).numerical_value_in(common::unit); const auto maxXYOne = std::max({typename T::rep{1}, abs(x), abs(y)}); return abs(x - y) <= std::numeric_limits::epsilon() * maxXYOne; } diff --git a/test/unit_test/runtime/linear_algebra_test.cpp b/test/unit_test/runtime/linear_algebra_test.cpp index ff642e77b..ad9fb31f4 100644 --- a/test/unit_test/runtime/linear_algebra_test.cpp +++ b/test/unit_test/runtime/linear_algebra_test.cpp @@ -118,14 +118,14 @@ TEST_CASE("vector quantity", "[la]") SECTION("integral") { - SECTION("scalar on LHS") { CHECK((2 * v).numerical_value_ref_in(m) == vector{2, 4, 6}); } - SECTION("scalar on RHS") { CHECK((v * 2).numerical_value_ref_in(m) == vector{2, 4, 6}); } + SECTION("scalar on LHS") { CHECK((2 * v).numerical_value_ == vector{2, 4, 6}); } + SECTION("scalar on RHS") { CHECK((v * 2).numerical_value_ == vector{2, 4, 6}); } } SECTION("floating-point") { - SECTION("scalar on LHS") { CHECK((0.5 * v).numerical_value_ref_in(m) == vector{0.5, 1., 1.5}); } - SECTION("scalar on RHS") { CHECK((v * 0.5).numerical_value_ref_in(m) == vector{0.5, 1., 1.5}); } + SECTION("scalar on LHS") { CHECK((0.5 * v).numerical_value_ == vector{0.5, 1., 1.5}); } + SECTION("scalar on RHS") { CHECK((v * 0.5).numerical_value_ == vector{0.5, 1., 1.5}); } } } @@ -133,8 +133,8 @@ TEST_CASE("vector quantity", "[la]") { const auto v = vector{2, 4, 6} * isq::position_vector[m]; - SECTION("integral") { CHECK((v / 2).numerical_value_ref_in(m) == vector{1, 2, 3}); } - SECTION("floating-point") { CHECK((v / 0.5).numerical_value_ref_in(m) == vector{4., 8., 12.}); } + SECTION("integral") { CHECK((v / 2).numerical_value_ == vector{1, 2, 3}); } + SECTION("floating-point") { CHECK((v / 0.5).numerical_value_ == vector{4., 8., 12.}); } } SECTION("add") @@ -144,12 +144,12 @@ TEST_CASE("vector quantity", "[la]") SECTION("same unit") { const auto u = vector{3, 2, 1} * isq::position_vector[m]; - CHECK((v + u).numerical_value_ref_in(m) == vector{4, 4, 4}); + CHECK((v + u).numerical_value_ == vector{4, 4, 4}); } SECTION("different units") { const auto u = vector{3, 2, 1} * isq::position_vector[km]; - CHECK((v + u).numerical_value_ref_in(m) == vector{3001, 2002, 1003}); + CHECK((v + u).numerical_value_ == vector{3001, 2002, 1003}); } } @@ -160,12 +160,12 @@ TEST_CASE("vector quantity", "[la]") SECTION("same unit") { const auto u = vector{3, 2, 1} * isq::position_vector[m]; - CHECK((v - u).numerical_value_ref_in(m) == vector{-2, 0, 2}); + CHECK((v - u).numerical_value_ == vector{-2, 0, 2}); } SECTION("different units") { const auto u = vector{3, 2, 1} * isq::position_vector[km]; - CHECK((v - u).numerical_value_ref_in(m) == vector{-2999, -1998, -997}); + CHECK((v - u).numerical_value_ == vector{-2999, -1998, -997}); } } @@ -179,18 +179,18 @@ TEST_CASE("vector quantity", "[la]") SECTION("derived_quantity_spec") { - SECTION("scalar on LHS") { CHECK((mass * v).numerical_value_ref_in(N * s) == vector{2, 4, 6}); } - SECTION("scalar on RHS") { CHECK((v * mass).numerical_value_ref_in(N * s) == vector{2, 4, 6}); } + SECTION("scalar on LHS") { CHECK((mass * v).numerical_value_ == vector{2, 4, 6}); } + SECTION("scalar on RHS") { CHECK((v * mass).numerical_value_ == vector{2, 4, 6}); } } SECTION("quantity_cast to momentum") { SECTION("scalar on LHS") { - CHECK(quantity_cast(mass * v).numerical_value_ref_in(N * s) == vector{2, 4, 6}); + CHECK(quantity_cast(mass * v).numerical_value_ == vector{2, 4, 6}); } SECTION("scalar on RHS") { - CHECK(quantity_cast(v * mass).numerical_value_ref_in(N * s) == vector{2, 4, 6}); + CHECK(quantity_cast(v * mass).numerical_value_ == vector{2, 4, 6}); } } SECTION("quantity of momentum") @@ -198,12 +198,12 @@ TEST_CASE("vector quantity", "[la]") SECTION("scalar on LHS") { const quantity> momentum = mass * v; - CHECK(momentum.numerical_value_ref_in(N * s) == vector{2, 4, 6}); + CHECK(momentum.numerical_value_ == vector{2, 4, 6}); } SECTION("scalar on RHS") { const quantity> momentum = v * mass; - CHECK(momentum.numerical_value_ref_in(N * s) == vector{2, 4, 6}); + CHECK(momentum.numerical_value_ == vector{2, 4, 6}); } } } @@ -214,18 +214,18 @@ TEST_CASE("vector quantity", "[la]") SECTION("derived_quantity_spec") { - SECTION("scalar on LHS") { CHECK((mass * v).numerical_value_ref_in(N * s) == vector{0.5, 1., 1.5}); } - SECTION("scalar on RHS") { CHECK((v * mass).numerical_value_ref_in(N * s) == vector{0.5, 1., 1.5}); } + SECTION("scalar on LHS") { CHECK((mass * v).numerical_value_ == vector{0.5, 1., 1.5}); } + SECTION("scalar on RHS") { CHECK((v * mass).numerical_value_ == vector{0.5, 1., 1.5}); } } SECTION("quantity_cast to momentum") { SECTION("scalar on LHS") { - CHECK(quantity_cast(mass * v).numerical_value_ref_in(N * s) == vector{0.5, 1., 1.5}); + CHECK(quantity_cast(mass * v).numerical_value_ == vector{0.5, 1., 1.5}); } SECTION("scalar on RHS") { - CHECK(quantity_cast(v * mass).numerical_value_ref_in(N * s) == vector{0.5, 1., 1.5}); + CHECK(quantity_cast(v * mass).numerical_value_ == vector{0.5, 1., 1.5}); } } SECTION("quantity of momentum") @@ -233,12 +233,12 @@ TEST_CASE("vector quantity", "[la]") SECTION("scalar on LHS") { const quantity> momentum = mass * v; - CHECK(momentum.numerical_value_ref_in(N * s) == vector{0.5, 1., 1.5}); + CHECK(momentum.numerical_value_ == vector{0.5, 1., 1.5}); } SECTION("scalar on RHS") { const quantity> momentum = v * mass; - CHECK(momentum.numerical_value_ref_in(N * s) == vector{0.5, 1., 1.5}); + CHECK(momentum.numerical_value_ == vector{0.5, 1., 1.5}); } } } @@ -252,15 +252,15 @@ TEST_CASE("vector quantity", "[la]") { const auto dur = 2 * isq::duration[h]; - SECTION("derived_quantity_spec") { CHECK((pos / dur).numerical_value_ref_in(km / h) == vector{15, 10, 5}); } + SECTION("derived_quantity_spec") { CHECK((pos / dur).numerical_value_ == vector{15, 10, 5}); } SECTION("quantity_cast to velocity") { - CHECK(quantity_cast(pos / dur).numerical_value_ref_in(km / h) == vector{15, 10, 5}); + CHECK(quantity_cast(pos / dur).numerical_value_ == vector{15, 10, 5}); } SECTION("quantity of velocity") { const quantity> v = pos / dur; - CHECK(v.numerical_value_ref_in(km / h) == vector{15, 10, 5}); + CHECK(v.numerical_value_ == vector{15, 10, 5}); } } @@ -268,18 +268,15 @@ TEST_CASE("vector quantity", "[la]") { const auto dur = 0.5 * isq::duration[h]; - SECTION("derived_quantity_spec") - { - CHECK((pos / dur).numerical_value_ref_in(km / h) == vector{60, 40, 20}); - } + SECTION("derived_quantity_spec") { CHECK((pos / dur).numerical_value_ == vector{60, 40, 20}); } SECTION("quantity_cast to velocity") { - CHECK(quantity_cast(pos / dur).numerical_value_ref_in(km / h) == vector{60, 40, 20}); + CHECK(quantity_cast(pos / dur).numerical_value_ == vector{60, 40, 20}); } SECTION("quantity of velocity") { const quantity> v = pos / dur; - CHECK(v.numerical_value_ref_in(km / h) == vector{60, 40, 20}); + CHECK(v.numerical_value_ == vector{60, 40, 20}); } } } diff --git a/test/unit_test/runtime/math_test.cpp b/test/unit_test/runtime/math_test.cpp index 3391e9007..fdf5e1dc3 100644 --- a/test/unit_test/runtime/math_test.cpp +++ b/test/unit_test/runtime/math_test.cpp @@ -90,13 +90,12 @@ TEST_CASE("numeric_limits functions", "[limits]") { SECTION("'epsilon' works as expected using default floating type") { - REQUIRE(epsilon(isq::length[m]).numerical_value_ref_in(m) == + REQUIRE(epsilon(isq::length[m]).numerical_value_ == std::numeric_limits::epsilon()); } SECTION("'epsilon' works as expected using integers") { - REQUIRE(epsilon(isq::length[m]).numerical_value_ref_in(m) == - + REQUIRE(epsilon(isq::length[m]).numerical_value_ == std::numeric_limits::epsilon()); } } diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/unit_test/static/quantity_point_test.cpp index 7805b2c1f..f7c5eb316 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -242,24 +242,22 @@ static_assert( //////////////////////////// static_assert( - quantity_point::zero().quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 0); + quantity_point::zero().quantity_ref_from(mean_sea_level).numerical_value_ == 0); static_assert( - quantity_point::min().quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == + quantity_point::min().quantity_ref_from(mean_sea_level).numerical_value_ == std::numeric_limits::lowest()); static_assert( - quantity_point::max().quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == + quantity_point::max().quantity_ref_from(mean_sea_level).numerical_value_ == std::numeric_limits::max()); static_assert( - quantity_point::zero().quantity_ref_from(ground_level).numerical_value_ref_in(m) == - 0); + quantity_point::zero().quantity_ref_from(ground_level).numerical_value_ == 0); static_assert( - quantity_point::min().quantity_ref_from(ground_level).numerical_value_ref_in(m) == + quantity_point::min().quantity_ref_from(ground_level).numerical_value_ == std::numeric_limits::lowest()); static_assert( - quantity_point::max().quantity_ref_from(ground_level).numerical_value_ref_in(m) == + quantity_point::max().quantity_ref_from(ground_level).numerical_value_ == std::numeric_limits::max()); @@ -591,15 +589,15 @@ static_assert(is_of_type<(ground_level + isq::height(short(42) * m)).point_for(m // converting to a different unit /////////////////////////////////// -static_assert((mean_sea_level + 2. * km).in(km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(km) == 2.); -static_assert((mean_sea_level + 2. * km).in(m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2000.); -static_assert((mean_sea_level + 2000. * m).in(km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(km) == 2.); -static_assert((ground_level + 2. * km).in(km).quantity_ref_from(ground_level).numerical_value_ref_in(km) == 2.); -static_assert((ground_level + 2. * km).in(m).quantity_ref_from(ground_level).numerical_value_ref_in(m) == 2000.); -static_assert((ground_level + 2000. * m).in(km).quantity_ref_from(ground_level).numerical_value_ref_in(km) == 2.); -static_assert((tower_peak + 2. * km).in(km).quantity_ref_from(tower_peak).numerical_value_ref_in(km) == 2.); -static_assert((tower_peak + 2. * km).in(m).quantity_ref_from(tower_peak).numerical_value_ref_in(m) == 2000.); -static_assert((tower_peak + 2000. * m).in(km).quantity_ref_from(tower_peak).numerical_value_ref_in(km) == 2.); +static_assert((mean_sea_level + 2. * km).in(km).quantity_ref_from(mean_sea_level).numerical_value_ == 2.); +static_assert((mean_sea_level + 2. * km).in(m).quantity_ref_from(mean_sea_level).numerical_value_ == 2000.); +static_assert((mean_sea_level + 2000. * m).in(km).quantity_ref_from(mean_sea_level).numerical_value_ == 2.); +static_assert((ground_level + 2. * km).in(km).quantity_ref_from(ground_level).numerical_value_ == 2.); +static_assert((ground_level + 2. * km).in(m).quantity_ref_from(ground_level).numerical_value_ == 2000.); +static_assert((ground_level + 2000. * m).in(km).quantity_ref_from(ground_level).numerical_value_ == 2.); +static_assert((tower_peak + 2. * km).in(km).quantity_ref_from(tower_peak).numerical_value_ == 2.); +static_assert((tower_peak + 2. * km).in(m).quantity_ref_from(tower_peak).numerical_value_ == 2000.); +static_assert((tower_peak + 2000. * m).in(km).quantity_ref_from(tower_peak).numerical_value_ == 2.); #if MP_UNITS_COMP_GCC != 10 || MP_UNITS_COMP_GCC_MINOR > 2 template typename QP> @@ -672,14 +670,14 @@ static_assert([](auto v) { //////////////////////// // same type -static_assert((mean_sea_level + 1 * m += 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2); -static_assert((mean_sea_level + 2 * m -= 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1); +static_assert((mean_sea_level + 1 * m += 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 2); +static_assert((mean_sea_level + 2 * m -= 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1); // different types -static_assert((mean_sea_level + 2.5 * m += 3 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 5.5); -static_assert((mean_sea_level + 123 * m += 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1123); -static_assert((mean_sea_level + 5.5 * m -= 3 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2.5); -static_assert((mean_sea_level + 1123 * m -= 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 123); +static_assert((mean_sea_level + 2.5 * m += 3 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 5.5); +static_assert((mean_sea_level + 123 * m += 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ == 1123); +static_assert((mean_sea_level + 5.5 * m -= 3 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 2.5); +static_assert((mean_sea_level + 1123 * m -= 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ == 123); template typename QP> @@ -952,30 +950,30 @@ static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), qu // check for integral types promotion static_assert(is_same_v); + .numerical_value_), + int>); static_assert(is_same_v); + .numerical_value_), + int>); static_assert(is_same_v); -static_assert(is_same_v); + .numerical_value_), + int>); +static_assert( + is_same_v< + decltype(((mean_sea_level + std::uint8_t(0) * m) - (mean_sea_level + std::uint8_t(0) * m)).numerical_value_), int>); static_assert(((mean_sea_level + std::uint8_t(128) * m) + std::uint8_t(128) * m) .quantity_ref_from(mean_sea_level) - .numerical_value_ref_in(m) == std::uint8_t(128) + std::uint8_t(128)); + .numerical_value_ == std::uint8_t(128) + std::uint8_t(128)); static_assert((std::uint8_t(128) * m + (mean_sea_level + std::uint8_t(128) * m)) .quantity_ref_from(mean_sea_level) - .numerical_value_ref_in(m) == std::uint8_t(128) + std::uint8_t(128)); -static_assert(((mean_sea_level + std::uint8_t(0) * m) - std::uint8_t(1) * m) - .quantity_ref_from(mean_sea_level) - .numerical_value_ref_in(m) == std::uint8_t(0) - std::uint8_t(1)); -static_assert(((mean_sea_level + std::uint8_t(0) * m) - (mean_sea_level + std::uint8_t(1) * m)) - .numerical_value_ref_in(m) == std::uint8_t(0) - std::uint8_t(1)); + .numerical_value_ == std::uint8_t(128) + std::uint8_t(128)); +static_assert( + ((mean_sea_level + std::uint8_t(0) * m) - std::uint8_t(1) * m).quantity_ref_from(mean_sea_level).numerical_value_ == + std::uint8_t(0) - std::uint8_t(1)); +static_assert(((mean_sea_level + std::uint8_t(0) * m) - (mean_sea_level + std::uint8_t(1) * m)).numerical_value_ == + std::uint8_t(0) - std::uint8_t(1)); // different representation types static_assert(is_of_type<(mean_sea_level + 1. * m) + 1 * m, quantity_point>); @@ -1029,49 +1027,39 @@ static_assert(is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + 1. * m), static_assert(is_of_type<(mean_sea_level + 1. * km) - (mean_sea_level + 1. * m), quantity>); -static_assert(((mean_sea_level + 1 * m) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2); -static_assert((1 * m + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2); -static_assert(((mean_sea_level + 1 * m) + 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1001); -static_assert((1 * m + (mean_sea_level + 1 * km)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1001); -static_assert(((mean_sea_level + 1 * km) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1001); -static_assert((1 * km + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1001); -static_assert(((mean_sea_level + 2 * m) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1); -static_assert(((mean_sea_level + 1 * km) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 999); - -static_assert(((mean_sea_level + 1.5 * m) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2.5); -static_assert((1.5 * m + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2.5); -static_assert(((mean_sea_level + 1.5 * m) + 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1001.5); -static_assert((1.5 * m + (mean_sea_level + 1 * km)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1001.5); -static_assert(((mean_sea_level + 1.5 * km) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1501); -static_assert((1.5 * km + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1501); -static_assert(((mean_sea_level + 2.5 * m) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 1.5); -static_assert(((mean_sea_level + 1.5 * km) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1499); - -static_assert(((mean_sea_level + 1 * m) + 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2.5); -static_assert((1 * m + (mean_sea_level + 1.5 * m)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 2.5); -static_assert(((mean_sea_level + 1 * m) + 1.5 * km).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1501); -static_assert((1 * m + (mean_sea_level + 1.5 * km)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1501); -static_assert(((mean_sea_level + 1 * km) + 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1001.5); -static_assert((1 * km + (mean_sea_level + 1.5 * m)).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 1001.5); -static_assert(((mean_sea_level + 2 * m) - 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == 0.5); -static_assert(((mean_sea_level + 1 * km) - 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ref_in(m) == - 998.5); - -static_assert(((mean_sea_level + 2 * m) - (mean_sea_level + 1 * m)).numerical_value_ref_in(m) == 1); -static_assert(((mean_sea_level + 1 * km) - (mean_sea_level + 1 * m)).numerical_value_ref_in(m) == 999); -static_assert(((mean_sea_level + 2.5 * m) - (mean_sea_level + 1 * m)).numerical_value_ref_in(m) == 1.5); -static_assert(((mean_sea_level + 1.5 * km) - (mean_sea_level + 1 * m)).numerical_value_ref_in(m) == 1499); -static_assert(((mean_sea_level + 2 * m) - (mean_sea_level + 1.5 * m)).numerical_value_ref_in(m) == 0.5); -static_assert(((mean_sea_level + 1 * km) - (mean_sea_level + 1.5 * m)).numerical_value_ref_in(m) == 998.5); +static_assert(((mean_sea_level + 1 * m) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 2); +static_assert((1 * m + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ == 2); +static_assert(((mean_sea_level + 1 * m) + 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ == 1001); +static_assert((1 * m + (mean_sea_level + 1 * km)).quantity_ref_from(mean_sea_level).numerical_value_ == 1001); +static_assert(((mean_sea_level + 1 * km) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1001); +static_assert((1 * km + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ == 1001); +static_assert(((mean_sea_level + 2 * m) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1); +static_assert(((mean_sea_level + 1 * km) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 999); + +static_assert(((mean_sea_level + 1.5 * m) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 2.5); +static_assert((1.5 * m + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ == 2.5); +static_assert(((mean_sea_level + 1.5 * m) + 1 * km).quantity_ref_from(mean_sea_level).numerical_value_ == 1001.5); +static_assert((1.5 * m + (mean_sea_level + 1 * km)).quantity_ref_from(mean_sea_level).numerical_value_ == 1001.5); +static_assert(((mean_sea_level + 1.5 * km) + 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1501); +static_assert((1.5 * km + (mean_sea_level + 1 * m)).quantity_ref_from(mean_sea_level).numerical_value_ == 1501); +static_assert(((mean_sea_level + 2.5 * m) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1.5); +static_assert(((mean_sea_level + 1.5 * km) - 1 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1499); + +static_assert(((mean_sea_level + 1 * m) + 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 2.5); +static_assert((1 * m + (mean_sea_level + 1.5 * m)).quantity_ref_from(mean_sea_level).numerical_value_ == 2.5); +static_assert(((mean_sea_level + 1 * m) + 1.5 * km).quantity_ref_from(mean_sea_level).numerical_value_ == 1501); +static_assert((1 * m + (mean_sea_level + 1.5 * km)).quantity_ref_from(mean_sea_level).numerical_value_ == 1501); +static_assert(((mean_sea_level + 1 * km) + 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 1001.5); +static_assert((1 * km + (mean_sea_level + 1.5 * m)).quantity_ref_from(mean_sea_level).numerical_value_ == 1001.5); +static_assert(((mean_sea_level + 2 * m) - 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 0.5); +static_assert(((mean_sea_level + 1 * km) - 1.5 * m).quantity_ref_from(mean_sea_level).numerical_value_ == 998.5); + +static_assert(((mean_sea_level + 2 * m) - (mean_sea_level + 1 * m)).numerical_value_ == 1); +static_assert(((mean_sea_level + 1 * km) - (mean_sea_level + 1 * m)).numerical_value_ == 999); +static_assert(((mean_sea_level + 2.5 * m) - (mean_sea_level + 1 * m)).numerical_value_ == 1.5); +static_assert(((mean_sea_level + 1.5 * km) - (mean_sea_level + 1 * m)).numerical_value_ == 1499); +static_assert(((mean_sea_level + 2 * m) - (mean_sea_level + 1.5 * m)).numerical_value_ == 0.5); +static_assert(((mean_sea_level + 1 * km) - (mean_sea_level + 1.5 * m)).numerical_value_ == 998.5); static_assert((mean_sea_level + 42 * m) - (ground_level + 42 * m) == -42 * m); static_assert((ground_level + 42 * m) - (mean_sea_level + 42 * m) == 42 * m); diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index 3d04f7546..77091cb73 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -112,15 +112,14 @@ static_assert(is_same_v::rep, int>); // static member functions //////////////////////////// -static_assert(quantity::zero().numerical_value_ref_in(m) == 0); -static_assert(quantity::one().numerical_value_ref_in(m) == 1); -static_assert(quantity::min().numerical_value_ref_in(m) == std::numeric_limits::lowest()); -static_assert(quantity::max().numerical_value_ref_in(m) == std::numeric_limits::max()); -static_assert(quantity::zero().numerical_value_ref_in(m) == 0.0); -static_assert(quantity::one().numerical_value_ref_in(m) == 1.0); -static_assert(quantity::min().numerical_value_ref_in(m) == - std::numeric_limits::lowest()); -static_assert(quantity::max().numerical_value_ref_in(m) == std::numeric_limits::max()); +static_assert(quantity::zero().numerical_value_ == 0); +static_assert(quantity::one().numerical_value_ == 1); +static_assert(quantity::min().numerical_value_ == std::numeric_limits::lowest()); +static_assert(quantity::max().numerical_value_ == std::numeric_limits::max()); +static_assert(quantity::zero().numerical_value_ == 0.0); +static_assert(quantity::one().numerical_value_ == 1.0); +static_assert(quantity::min().numerical_value_ == std::numeric_limits::lowest()); +static_assert(quantity::max().numerical_value_ == std::numeric_limits::max()); ////////////////////////////// @@ -191,10 +190,10 @@ static_assert(std::convertible_to, quantity(123 * m).numerical_value_ref_in(m) == 123); -static_assert(quantity(2 * km).numerical_value_ref_in(m) == 2000); -static_assert(quantity(2 * km).numerical_value_ref_in(km) == 2); -static_assert(quantity(1500 * m).numerical_value_ref_in(km) == 1.5); +static_assert(quantity(123 * m).numerical_value_ == 123); +static_assert(quantity(2 * km).numerical_value_ == 2000); +static_assert(quantity(2 * km).numerical_value_ == 2); +static_assert(quantity(1500 * m).numerical_value_ == 1.5); /////////////////////////////////// @@ -205,11 +204,11 @@ static_assert(is_of_type<(2. * km).in(m), quantity>); static_assert(is_of_type>); static_assert(is_of_type>); -static_assert(quantity(2. * km).in(km).numerical_value_ref_in(km) == 2.); -static_assert(quantity(2. * km).in(m).numerical_value_ref_in(m) == 2000.); -static_assert(quantity(2000. * m).in(km).numerical_value_ref_in(km) == 2.); -static_assert(quantity(2 * km).in(km).numerical_value_ref_in(km) == 2); -static_assert(quantity(2 * km).in(m).numerical_value_ref_in(m) == 2000); +static_assert(quantity(2. * km).in(km).numerical_value_ == 2.); +static_assert(quantity(2. * km).in(m).numerical_value_ == 2000.); +static_assert(quantity(2000. * m).in(km).numerical_value_ == 2.); +static_assert(quantity(2 * km).in(km).numerical_value_ == 2); +static_assert(quantity(2 * km).in(m).numerical_value_ == 2000); #if MP_UNITS_COMP_GCC != 10 || MP_UNITS_COMP_GCC_MINOR > 2 template typename Q> @@ -309,28 +308,28 @@ static_assert([] { auto l1(1 * m), l2(2 * m); return l2 = l1; }() - .numerical_value_ref_in(m) == 1); + .numerical_value_ == 1); static_assert([] { const auto l1(1 * m); auto l2(2 * m); return l2 = l1; }() - .numerical_value_ref_in(m) == 1); + .numerical_value_ == 1); static_assert([]() { auto l1(1 * m), l2(2 * m); return l2 = std::move(l1); }() - .numerical_value_ref_in(m) == 1); + .numerical_value_ == 1); //////////////////// // unary operators //////////////////// -static_assert((+123 * m).numerical_value_ref_in(m) == 123); -static_assert((-123 * m).numerical_value_ref_in(m) == -123); -static_assert((+(-123 * m)).numerical_value_ref_in(m) == -123); -static_assert((-(-123 * m)).numerical_value_ref_in(m) == 123); +static_assert((+123 * m).numerical_value_ == 123); +static_assert((-123 * m).numerical_value_ == -123); +static_assert((+(-123 * m)).numerical_value_ == -123); +static_assert((-(-123 * m)).numerical_value_ == 123); static_assert([](auto v) { auto vv = v++; @@ -349,7 +348,7 @@ static_assert([](auto v) { return std::pair(v, vv); }(123 * m) == std::pair(122 * m, 122 * m)); -static_assert(is_same_v); +static_assert(is_same_v); //////////////////////// @@ -357,30 +356,31 @@ static_assert(is_same_v typename Q> @@ -518,15 +518,14 @@ static_assert(is_of_type<1 * km % (300 * m), quantity>); static_assert(is_of_type<4 * one % (2 * one), quantity>); // check for integral types promotion -static_assert(is_same_v); -static_assert(is_same_v); -static_assert((std::uint8_t(128) * m + std::uint8_t(128) * m).numerical_value_ref_in(m) == +static_assert(is_same_v); +static_assert(is_same_v); +static_assert((std::uint8_t(128) * m + std::uint8_t(128) * m).numerical_value_ == std::uint8_t(128) + std::uint8_t(128)); -static_assert((std::uint8_t(0) * m - std::uint8_t(1) * m).numerical_value_ref_in(m) == - std::uint8_t(0) - std::uint8_t(1)); +static_assert((std::uint8_t(0) * m - std::uint8_t(1) * m).numerical_value_ == std::uint8_t(0) - std::uint8_t(1)); -static_assert(is_same_v); +static_assert( + is_same_v); // different representation types static_assert(is_of_type<1. * m + 1 * m, quantity>); @@ -599,67 +598,67 @@ static_assert(is_of_type<1 * m / (1 * s), quantity>{}, int>>); static_assert(is_of_type<1 * min / (1 * m), quantity>{}, int>>); -static_assert((1 * m + 1 * m).numerical_value_ref_in(m) == 2); -static_assert((1 * m + 1 * km).numerical_value_ref_in(m) == 1001); -static_assert((1 * km + 1 * m).numerical_value_ref_in(m) == 1001); -static_assert((2 * m - 1 * m).numerical_value_ref_in(m) == 1); -static_assert((1 * km - 1 * m).numerical_value_ref_in(m) == 999); -static_assert((2 * m * 2).numerical_value_ref_in(m) == 4); -static_assert((2 * m * (2 * one)).numerical_value_ref_in(m) == 4); -static_assert((2 * m * (2 * percent)).numerical_value_ref_in(m * percent) == 4); -static_assert((3 * 3 * m).numerical_value_ref_in(m) == 9); -static_assert(((3 * one) * (3 * m)).numerical_value_ref_in(m) == 9); -static_assert(((3 * percent) * (3 * m)).numerical_value_ref_in(m * percent) == 9); -static_assert((4 * m / 2).numerical_value_ref_in(m) == 2); -static_assert((4 * m / (2 * one)).numerical_value_ref_in(m) == 2); -static_assert((4 * m / (2 * percent)).numerical_value_ref_in(m / percent) == 2); -static_assert((4 * km / (2 * m)).numerical_value_ref_in(km / m) == 2); -static_assert((4000 * m / (2 * m)).numerical_value_ref_in(one) == 2000); - -static_assert((1.5 * m + 1 * m).numerical_value_ref_in(m) == 2.5); -static_assert((1.5 * m + 1 * km).numerical_value_ref_in(m) == 1001.5); -static_assert((1.5 * km + 1 * m).numerical_value_ref_in(m) == 1501); -static_assert((2.5 * m - 1 * m).numerical_value_ref_in(m) == 1.5); -static_assert((1.5 * km - 1 * m).numerical_value_ref_in(m) == 1499); -static_assert((2.5 * m * 2).numerical_value_ref_in(m) == 5); -static_assert((2.5 * m * (2 * one)).numerical_value_ref_in(m) == 5); -static_assert((2.5 * m * (2 * percent)).numerical_value_ref_in(m * percent) == 5); -static_assert((2.5L * (2 * m)).numerical_value_ref_in(m) == 5); -static_assert((2.5L * one * (2 * m)).numerical_value_ref_in(m) == 5); -static_assert((2.5L * percent * (2 * m)).numerical_value_ref_in(m * percent) == 5); -static_assert((5. * m / 2).numerical_value_ref_in(m) == 2.5); -static_assert((5. * m / (2 * one)).numerical_value_ref_in(m) == 2.5); -static_assert((5. * m / (2 * percent)).numerical_value_ref_in(m / percent) == 2.5); -static_assert((5. * km / (2 * m)).numerical_value_ref_in(km / m) == 2.5); -static_assert((5000. * m / (2 * m)).numerical_value_ref_in(one) == 2500); - -static_assert((1 * m + 1.5 * m).numerical_value_ref_in(m) == 2.5); -static_assert((1 * m + 1.5 * km).numerical_value_ref_in(m) == 1501); -static_assert((1 * km + 1.5 * m).numerical_value_ref_in(m) == 1001.5); -static_assert((2 * m - 1.5 * m).numerical_value_ref_in(m) == 0.5); -static_assert((1 * km - 1.5 * m).numerical_value_ref_in(m) == 998.5); -static_assert((2 * m * 2.5L).numerical_value_ref_in(m) == 5); -static_assert((2 * m * (2.5L * one)).numerical_value_ref_in(m) == 5); -static_assert((2 * m * (2.5L * percent)).numerical_value_ref_in(m * percent) == 5); -static_assert((2 * 2.5 * m).numerical_value_ref_in(m) == 5); -static_assert((2 * one * (2.5 * m)).numerical_value_ref_in(m) == 5); -static_assert((2 * percent * (2.5 * m)).numerical_value_ref_in(m * percent) == 5); -static_assert((5 * m / 2.5L).numerical_value_ref_in(m) == 2); -static_assert((5 * m / (2.5L * one)).numerical_value_ref_in(m) == 2); -static_assert((5 * m / (2.5L * percent)).numerical_value_ref_in(m / percent) == 2); -static_assert((5 * km / (2.5 * m)).numerical_value_ref_in(km / m) == 2); -static_assert((5000 * m / (2.5 * m)).numerical_value_ref_in(one) == 2000); - -static_assert((7 * m % (2 * m)).numerical_value_ref_in(m) == 1); -static_assert((7 * km % (2000 * m)).numerical_value_ref_in(m) == 1000); -static_assert((1300 * m % (1 * km)).numerical_value_ref_in(m) == 300); -static_assert((7 * one % (2 * one)).numerical_value_ref_in(one) == 1); +static_assert((1 * m + 1 * m).numerical_value_ == 2); +static_assert((1 * m + 1 * km).numerical_value_ == 1001); +static_assert((1 * km + 1 * m).numerical_value_ == 1001); +static_assert((2 * m - 1 * m).numerical_value_ == 1); +static_assert((1 * km - 1 * m).numerical_value_ == 999); +static_assert((2 * m * 2).numerical_value_ == 4); +static_assert((2 * m * (2 * one)).numerical_value_ == 4); +static_assert((2 * m * (2 * percent)).numerical_value_ == 4); +static_assert((3 * 3 * m).numerical_value_ == 9); +static_assert(((3 * one) * (3 * m)).numerical_value_ == 9); +static_assert(((3 * percent) * (3 * m)).numerical_value_ == 9); +static_assert((4 * m / 2).numerical_value_ == 2); +static_assert((4 * m / (2 * one)).numerical_value_ == 2); +static_assert((4 * m / (2 * percent)).numerical_value_ == 2); +static_assert((4 * km / (2 * m)).numerical_value_ == 2); +static_assert((4000 * m / (2 * m)).numerical_value_ == 2000); + +static_assert((1.5 * m + 1 * m).numerical_value_ == 2.5); +static_assert((1.5 * m + 1 * km).numerical_value_ == 1001.5); +static_assert((1.5 * km + 1 * m).numerical_value_ == 1501); +static_assert((2.5 * m - 1 * m).numerical_value_ == 1.5); +static_assert((1.5 * km - 1 * m).numerical_value_ == 1499); +static_assert((2.5 * m * 2).numerical_value_ == 5); +static_assert((2.5 * m * (2 * one)).numerical_value_ == 5); +static_assert((2.5 * m * (2 * percent)).numerical_value_ == 5); +static_assert((2.5L * (2 * m)).numerical_value_ == 5); +static_assert((2.5L * one * (2 * m)).numerical_value_ == 5); +static_assert((2.5L * percent * (2 * m)).numerical_value_ == 5); +static_assert((5. * m / 2).numerical_value_ == 2.5); +static_assert((5. * m / (2 * one)).numerical_value_ == 2.5); +static_assert((5. * m / (2 * percent)).numerical_value_ == 2.5); +static_assert((5. * km / (2 * m)).numerical_value_ == 2.5); +static_assert((5000. * m / (2 * m)).numerical_value_ == 2500); + +static_assert((1 * m + 1.5 * m).numerical_value_ == 2.5); +static_assert((1 * m + 1.5 * km).numerical_value_ == 1501); +static_assert((1 * km + 1.5 * m).numerical_value_ == 1001.5); +static_assert((2 * m - 1.5 * m).numerical_value_ == 0.5); +static_assert((1 * km - 1.5 * m).numerical_value_ == 998.5); +static_assert((2 * m * 2.5L).numerical_value_ == 5); +static_assert((2 * m * (2.5L * one)).numerical_value_ == 5); +static_assert((2 * m * (2.5L * percent)).numerical_value_ == 5); +static_assert((2 * 2.5 * m).numerical_value_ == 5); +static_assert((2 * one * (2.5 * m)).numerical_value_ == 5); +static_assert((2 * percent * (2.5 * m)).numerical_value_ == 5); +static_assert((5 * m / 2.5L).numerical_value_ == 2); +static_assert((5 * m / (2.5L * one)).numerical_value_ == 2); +static_assert((5 * m / (2.5L * percent)).numerical_value_ == 2); +static_assert((5 * km / (2.5 * m)).numerical_value_ == 2); +static_assert((5000 * m / (2.5 * m)).numerical_value_ == 2000); + +static_assert((7 * m % (2 * m)).numerical_value_ == 1); +static_assert((7 * km % (2000 * m)).numerical_value_ == 1000); +static_assert((1300 * m % (1 * km)).numerical_value_ == 300); +static_assert((7 * one % (2 * one)).numerical_value_ == 1); static_assert((10 * m2 * (10 * m2)) / (50 * m2) == 2 * m2); -static_assert((10 * km / (5 * m)).numerical_value_ref_in(km / m) == 2); +static_assert((10 * km / (5 * m)).numerical_value_ == 2); static_assert((10 * km / (5 * m)).numerical_value_in(one) == 2000); -static_assert((10 * s * (2 * kHz)).numerical_value_ref_in(s * kHz) == 20); +static_assert((10 * s * (2 * kHz)).numerical_value_ == 20); // commutativity and associativity static_assert(10 * isq::length[si::metre] / (2 * isq::time[s]) + 5 * isq::speed[m / s] == 10 * isq::speed[m / s]); @@ -743,16 +742,13 @@ static_assert(is_same_v); static_assert(1 * one - 30 * percent == (100 - 30) * percent); static_assert(1 * one + 30 * percent == (100 + 30) * percent); -static_assert(is_same_v); -static_assert(is_same_v); -static_assert((std::uint8_t(128) * one + std::uint8_t(128) * one).numerical_value_ref_in(one) == - +static_assert(is_same_v); +static_assert(is_same_v); +static_assert((std::uint8_t(128) * one + std::uint8_t(128) * one).numerical_value_ == std::uint8_t(128) + std::uint8_t(128)); -static_assert((std::uint8_t(0) * one - std::uint8_t(1) * one).numerical_value_ref_in(one) == - std::uint8_t(0) - std::uint8_t(1)); - -static_assert(is_same_v); +static_assert((std::uint8_t(0) * one - std::uint8_t(1) * one).numerical_value_ == std::uint8_t(0) - std::uint8_t(1)); +static_assert(is_same_v); static_assert(2 * one * (1 * m) == 2 * m); static_assert(2 * one / (1 * m) == 2 / (1 * m)); @@ -895,14 +891,14 @@ static_assert((50. * percent).numerical_value_in(one) == 0.5); // value_cast ////////////////// -static_assert(value_cast(2 * km).numerical_value_ref_in(m) == 2000); -static_assert(value_cast(2000 * m).numerical_value_ref_in(km) == 2); -static_assert(value_cast(1.23 * m).numerical_value_ref_in(m) == 1); -static_assert(value_cast(2000.0 * m / (3600.0 * s)).numerical_value_ref_in(km / h) == 2); +static_assert(value_cast(2 * km).numerical_value_ == 2000); +static_assert(value_cast(2000 * m).numerical_value_ == 2); +static_assert(value_cast(1.23 * m).numerical_value_ == 1); +static_assert(value_cast(2000.0 * m / (3600.0 * s)).numerical_value_ == 2); -static_assert((2 * km).force_in(m).numerical_value_ref_in(m) == 2000); -static_assert((2000 * m).force_in(km).numerical_value_ref_in(km) == 2); -static_assert((2000.0 * m / (3600.0 * s)).force_in(km / h).numerical_value_ref_in(km / h) == 2); +static_assert((2 * km).force_in(m).numerical_value_ == 2000); +static_assert((2000 * m).force_in(km).numerical_value_ == 2); +static_assert((2000.0 * m / (3600.0 * s)).force_in(km / h).numerical_value_ == 2); ////////////////// // quantity_cast