refactor: ValuePreservingTo concept added

This commit is contained in:
Mateusz Pusz
2024-07-13 08:36:48 +02:00
parent 160a74a94a
commit fa25d11275

View File

@@ -59,12 +59,15 @@ template<Unit UFrom, Unit UTo>
template<typename T> template<typename T>
concept IsFloatingPoint = treat_as_floating_point<T>; concept IsFloatingPoint = treat_as_floating_point<T>;
template<typename FromRep, typename ToRep, auto FromUnit = one, auto ToUnit = one>
concept ValuePreservingTo =
IsFloatingPoint<ToRep> || (!IsFloatingPoint<FromRep> && (integral_conversion_factor(FromUnit, ToUnit)));
template<typename QFrom, typename QTo> template<typename QFrom, typename QTo>
concept QuantityConvertibleTo = concept QuantityConvertibleTo =
Quantity<QFrom> && Quantity<QTo> && detail::QuantitySpecConvertibleTo<QFrom::quantity_spec, QTo::quantity_spec> && Quantity<QFrom> && Quantity<QTo> && QuantitySpecConvertibleTo<QFrom::quantity_spec, QTo::quantity_spec> &&
detail::UnitConvertibleTo<QFrom::unit, QTo::unit> && UnitConvertibleTo<QFrom::unit, QTo::unit> &&
(IsFloatingPoint<typename QTo::rep> || ValuePreservingTo<typename QFrom::rep, typename QTo::rep, QFrom::unit, QTo::unit> &&
(!IsFloatingPoint<typename QFrom::rep> && (integral_conversion_factor(QFrom::unit, QTo::unit)))) &&
// TODO consider providing constraints of sudo_cast here rather than testing if it can be called (its return type is // 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) // deduced thus the function is evaluated here and may emit truncating conversion or other warnings)
requires(QFrom q) { detail::sudo_cast<QTo>(q); }; requires(QFrom q) { detail::sudo_cast<QTo>(q); };