From a89bfc6c2154cac17116fe548b107d569c90be14 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:14:42 +0200 Subject: [PATCH] [hacks] add MP_UNITS_IS_VALUE --- src/core/include/mp-units/bits/hacks.h | 2 ++ .../mp-units/framework/construction_helpers.h | 4 ++-- src/systems/include/mp-units/systems/si/chrono.h | 4 ++-- src/systems/include/mp-units/systems/si/math.h | 14 +++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 905aea8f..bbd3eec7 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -81,11 +81,13 @@ #define MP_UNITS_TYPENAME typename #define MP_UNITS_EXPRESSION(x) (x) +#define MP_UNITS_IS_VALUE(x) (x) #else #define MP_UNITS_TYPENAME #define MP_UNITS_EXPRESSION(x) x +#define MP_UNITS_IS_VALUE(x) #endif diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index c0226e47..43e44c81 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -41,7 +41,7 @@ template struct delta_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity<(R{}), std::remove_cvref_t> operator()(Rep&& lhs) const + [[nodiscard]] constexpr quantity> operator()(Rep&& lhs) const { return quantity{std::forward(lhs), R{}}; } @@ -51,7 +51,7 @@ template struct absolute_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point<(R{}), default_point_origin(R{}), std::remove_cvref_t> operator()( + [[nodiscard]] constexpr quantity_point> operator()( Rep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index 0fad31e1..c018e8d1 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -127,13 +127,13 @@ namespace detail { } // namespace detail -template Q> +template Q> [[nodiscard]] constexpr auto to_chrono_duration(const Q& q) { return std::chrono::duration{q}; } -template QP> +template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index 202ea76d..0a863585 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -43,7 +43,7 @@ import std; MP_UNITS_EXPORT namespace mp_units::si { -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { sin(v); } || requires(Rep v) { std::sin(v); } [[nodiscard]] inline QuantityOf auto sin(const quantity& q) noexcept { @@ -57,7 +57,7 @@ template auto R, typename Rep> return quantity{sin(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { cos(v); } || requires(Rep v) { std::cos(v); } [[nodiscard]] inline QuantityOf auto cos(const quantity& q) noexcept { @@ -71,7 +71,7 @@ template auto R, typename Rep> return quantity{cos(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { tan(v); } || requires(Rep v) { std::tan(v); } [[nodiscard]] inline QuantityOf auto tan(const quantity& q) noexcept { @@ -87,7 +87,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto asin(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -101,7 +101,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto acos(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -115,7 +115,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto atan(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { @@ -132,7 +132,7 @@ template common_reference(R1, R2); requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); }; } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto atan2(const quantity& y, +[[nodiscard]] inline QuantityOf auto atan2(const quantity& y, const quantity& x) noexcept { constexpr auto ref = common_reference(R1, R2);