From fa25d11275446fbaae1aee01806f8e7e770b2b8f Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 13 Jul 2024 08:36:48 +0200 Subject: [PATCH] refactor: `ValuePreservingTo` concept added --- src/core/include/mp-units/framework/quantity.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index d2acd5f6..7e404ce1 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -59,12 +59,15 @@ template template concept IsFloatingPoint = treat_as_floating_point; +template +concept ValuePreservingTo = + IsFloatingPoint || (!IsFloatingPoint && (integral_conversion_factor(FromUnit, ToUnit))); + template concept QuantityConvertibleTo = - Quantity && Quantity && detail::QuantitySpecConvertibleTo && - detail::UnitConvertibleTo && - (IsFloatingPoint || - (!IsFloatingPoint && (integral_conversion_factor(QFrom::unit, QTo::unit)))) && + Quantity && Quantity && QuantitySpecConvertibleTo && + UnitConvertibleTo && + ValuePreservingTo && // TODO consider providing constraints of sudo_cast here rather than testing if it can be called (its return type is // deduced thus the function is evaluated here and may emit truncating conversion or other warnings) requires(QFrom q) { detail::sudo_cast(q); };