mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
refactor: ValuePreservingScaling
concepts renamed
This commit is contained in:
@ -77,14 +77,14 @@ template<typename T, typename Arg>
|
|||||||
concept ValuePreservingAssignment = std::assignable_from<T&, Arg> && is_value_preserving<std::remove_cvref_t<Arg>, T>;
|
concept ValuePreservingAssignment = std::assignable_from<T&, Arg> && is_value_preserving<std::remove_cvref_t<Arg>, T>;
|
||||||
|
|
||||||
template<auto FromUnit, auto ToUnit, typename Rep>
|
template<auto FromUnit, auto ToUnit, typename Rep>
|
||||||
concept ValuePreservingScaling1Rep =
|
concept ValuePreservingScaling =
|
||||||
SaneScaling<FromUnit, ToUnit, Rep> &&
|
SaneScaling<FromUnit, ToUnit, Rep> &&
|
||||||
(treat_as_floating_point<Rep> || (integral_conversion_factor(FromUnit, ToUnit)) ||
|
(treat_as_floating_point<Rep> || (integral_conversion_factor(FromUnit, ToUnit)) ||
|
||||||
unsatisfied<"Scaling from '{}' to '{}' is not value-preserving for '{}' representation type">(
|
unsatisfied<"Scaling from '{}' to '{}' is not value-preserving for '{}' representation type">(
|
||||||
unit_symbol(FromUnit), unit_symbol(ToUnit), type_name<Rep>()));
|
unit_symbol(FromUnit), unit_symbol(ToUnit), type_name<Rep>()));
|
||||||
|
|
||||||
template<auto FromUnit, typename FromRep, auto ToUnit, typename ToRep>
|
template<auto FromUnit, typename FromRep, auto ToUnit, typename ToRep>
|
||||||
concept ValuePreservingScaling2Reps =
|
concept ValuePreservingConversion =
|
||||||
// TODO consider providing constraints of sudo_cast to check if representation types can be scaled between each other
|
// TODO consider providing constraints of sudo_cast to check if representation types can be scaled between each other
|
||||||
// CastableReps<FromRep, ToRep, FromUnit, ToUnit> &&
|
// CastableReps<FromRep, ToRep, FromUnit, ToUnit> &&
|
||||||
SaneScaling<FromUnit, ToUnit, ToRep> &&
|
SaneScaling<FromUnit, ToUnit, ToRep> &&
|
||||||
@ -97,7 +97,7 @@ template<typename QTo, typename QFrom>
|
|||||||
concept QuantityConstructibleFrom =
|
concept QuantityConstructibleFrom =
|
||||||
Quantity<QTo> && Quantity<QFrom> && explicitly_convertible(QFrom::quantity_spec, QTo::quantity_spec) &&
|
Quantity<QTo> && Quantity<QFrom> && explicitly_convertible(QFrom::quantity_spec, QTo::quantity_spec) &&
|
||||||
ValuePreservingConstruction<typename QTo::rep, typename QFrom::rep> &&
|
ValuePreservingConstruction<typename QTo::rep, typename QFrom::rep> &&
|
||||||
ValuePreservingScaling2Reps<QFrom::unit, typename QFrom::rep, QTo::unit, typename QTo::rep>;
|
ValuePreservingConversion<QFrom::unit, typename QFrom::rep, QTo::unit, typename QTo::rep>;
|
||||||
|
|
||||||
template<typename T, typename Rep>
|
template<typename T, typename Rep>
|
||||||
concept ScalarValuePreservingTo = (!Quantity<T>) && Scalar<T> && is_value_preserving<T, Rep>;
|
concept ScalarValuePreservingTo = (!Quantity<T>) && Scalar<T> && is_value_preserving<T, Rep>;
|
||||||
@ -245,7 +245,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<detail::WeakUnitOf<quantity_spec> ToU>
|
template<detail::WeakUnitOf<quantity_spec> ToU>
|
||||||
requires detail::ValuePreservingScaling1Rep<unit, ToU{}, rep>
|
requires detail::ValuePreservingScaling<unit, ToU{}, rep>
|
||||||
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto in(ToU) const
|
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto in(ToU) const
|
||||||
{
|
{
|
||||||
return quantity<detail::make_reference(quantity_spec, ToU{}), Rep>{*this};
|
return quantity<detail::make_reference(quantity_spec, ToU{}), Rep>{*this};
|
||||||
@ -260,7 +260,7 @@ public:
|
|||||||
|
|
||||||
template<RepresentationOf<quantity_spec> ToRep, detail::WeakUnitOf<quantity_spec> ToU>
|
template<RepresentationOf<quantity_spec> ToRep, detail::WeakUnitOf<quantity_spec> ToU>
|
||||||
requires detail::ValuePreservingConstruction<ToRep, rep> &&
|
requires detail::ValuePreservingConstruction<ToRep, rep> &&
|
||||||
detail::ValuePreservingScaling2Reps<unit, rep, ToU{}, ToRep>
|
detail::ValuePreservingConversion<unit, rep, ToU{}, ToRep>
|
||||||
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto in(ToU) const
|
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto in(ToU) const
|
||||||
{
|
{
|
||||||
return quantity<detail::make_reference(quantity_spec, ToU{}), ToRep>{*this};
|
return quantity<detail::make_reference(quantity_spec, ToU{}), ToRep>{*this};
|
||||||
@ -312,7 +312,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<detail::WeakUnitOf<quantity_spec> U>
|
template<detail::WeakUnitOf<quantity_spec> U>
|
||||||
requires detail::ValuePreservingScaling1Rep<unit, U{}, rep>
|
requires detail::ValuePreservingScaling<unit, U{}, rep>
|
||||||
[[nodiscard]] constexpr rep numerical_value_in(U) const noexcept
|
[[nodiscard]] constexpr rep numerical_value_in(U) const noexcept
|
||||||
{
|
{
|
||||||
return in(U{}).numerical_value_is_an_implementation_detail_;
|
return in(U{}).numerical_value_is_an_implementation_detail_;
|
||||||
@ -400,7 +400,7 @@ public:
|
|||||||
// compound assignment operators
|
// compound assignment operators
|
||||||
template<auto R2, typename Rep2>
|
template<auto R2, typename Rep2>
|
||||||
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
||||||
detail::ValuePreservingScaling2Reps<get_unit(R2), Rep2, unit, rep> && requires(rep& a, const Rep2 b) {
|
detail::ValuePreservingConversion<get_unit(R2), Rep2, unit, rep> && requires(rep& a, const Rep2 b) {
|
||||||
{ a += b } -> std::same_as<rep&>;
|
{ a += b } -> std::same_as<rep&>;
|
||||||
}
|
}
|
||||||
constexpr quantity& operator+=(const quantity<R2, Rep2>& other) &
|
constexpr quantity& operator+=(const quantity<R2, Rep2>& other) &
|
||||||
@ -414,7 +414,7 @@ public:
|
|||||||
|
|
||||||
template<auto R2, typename Rep2>
|
template<auto R2, typename Rep2>
|
||||||
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
||||||
detail::ValuePreservingScaling2Reps<get_unit(R2), Rep2, unit, rep> && requires(rep& a, const Rep2 b) {
|
detail::ValuePreservingConversion<get_unit(R2), Rep2, unit, rep> && requires(rep& a, const Rep2 b) {
|
||||||
{ a -= b } -> std::same_as<rep&>;
|
{ a -= b } -> std::same_as<rep&>;
|
||||||
}
|
}
|
||||||
constexpr quantity& operator-=(const quantity<R2, Rep2>& other) &
|
constexpr quantity& operator-=(const quantity<R2, Rep2>& other) &
|
||||||
@ -428,7 +428,7 @@ public:
|
|||||||
|
|
||||||
template<auto R2, typename Rep2>
|
template<auto R2, typename Rep2>
|
||||||
requires(!treat_as_floating_point<rep>) && (implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
requires(!treat_as_floating_point<rep>) && (implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
||||||
detail::ValuePreservingScaling2Reps<get_unit(R2), Rep2, unit, rep> && requires(rep& a, const Rep2 b) {
|
detail::ValuePreservingConversion<get_unit(R2), Rep2, unit, rep> && requires(rep& a, const Rep2 b) {
|
||||||
{ a %= b } -> std::same_as<rep&>;
|
{ a %= b } -> std::same_as<rep&>;
|
||||||
}
|
}
|
||||||
constexpr quantity& operator%=(const quantity<R2, Rep2>& other) &
|
constexpr quantity& operator%=(const quantity<R2, Rep2>& other) &
|
||||||
|
@ -329,7 +329,7 @@ public:
|
|||||||
|
|
||||||
// unit conversions
|
// unit conversions
|
||||||
template<detail::WeakUnitOf<quantity_spec> ToU>
|
template<detail::WeakUnitOf<quantity_spec> ToU>
|
||||||
requires detail::ValuePreservingScaling1Rep<unit, ToU{}, rep>
|
requires detail::ValuePreservingScaling<unit, ToU{}, rep>
|
||||||
[[nodiscard]] constexpr QuantityPointOf<quantity_spec> auto in(ToU) const
|
[[nodiscard]] constexpr QuantityPointOf<quantity_spec> auto in(ToU) const
|
||||||
{
|
{
|
||||||
return ::mp_units::quantity_point{quantity_ref_from(point_origin).in(ToU{}), point_origin};
|
return ::mp_units::quantity_point{quantity_ref_from(point_origin).in(ToU{}), point_origin};
|
||||||
@ -344,7 +344,7 @@ public:
|
|||||||
|
|
||||||
template<RepresentationOf<quantity_spec> ToRep, detail::WeakUnitOf<quantity_spec> ToU>
|
template<RepresentationOf<quantity_spec> ToRep, detail::WeakUnitOf<quantity_spec> ToU>
|
||||||
requires detail::ValuePreservingConstruction<ToRep, rep> &&
|
requires detail::ValuePreservingConstruction<ToRep, rep> &&
|
||||||
detail::ValuePreservingScaling2Reps<unit, rep, ToU{}, ToRep>
|
detail::ValuePreservingConversion<unit, rep, ToU{}, ToRep>
|
||||||
[[nodiscard]] constexpr QuantityPointOf<quantity_spec> auto in(ToU) const
|
[[nodiscard]] constexpr QuantityPointOf<quantity_spec> auto in(ToU) const
|
||||||
{
|
{
|
||||||
return ::mp_units::quantity_point{quantity_ref_from(point_origin).template in<ToRep>(ToU{}), point_origin};
|
return ::mp_units::quantity_point{quantity_ref_from(point_origin).template in<ToRep>(ToU{}), point_origin};
|
||||||
@ -438,7 +438,7 @@ public:
|
|||||||
// compound assignment operators
|
// compound assignment operators
|
||||||
template<auto R2, typename Rep2>
|
template<auto R2, typename Rep2>
|
||||||
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
||||||
detail::ValuePreservingScaling2Reps<get_unit(R2), Rep2, unit, rep> &&
|
detail::ValuePreservingConversion<get_unit(R2), Rep2, unit, rep> &&
|
||||||
requires(const quantity_type q) { quantity_from_origin_is_an_implementation_detail_ += q; }
|
requires(const quantity_type q) { quantity_from_origin_is_an_implementation_detail_ += q; }
|
||||||
constexpr quantity_point& operator+=(const quantity<R2, Rep2>& q) &
|
constexpr quantity_point& operator+=(const quantity<R2, Rep2>& q) &
|
||||||
{
|
{
|
||||||
@ -448,7 +448,7 @@ public:
|
|||||||
|
|
||||||
template<auto R2, typename Rep2>
|
template<auto R2, typename Rep2>
|
||||||
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
requires(implicitly_convertible(get_quantity_spec(R2), quantity_spec)) &&
|
||||||
detail::ValuePreservingScaling2Reps<get_unit(R2), Rep2, unit, rep> &&
|
detail::ValuePreservingConversion<get_unit(R2), Rep2, unit, rep> &&
|
||||||
requires(const quantity_type q) { quantity_from_origin_is_an_implementation_detail_ -= q; }
|
requires(const quantity_type q) { quantity_from_origin_is_an_implementation_detail_ -= q; }
|
||||||
constexpr quantity_point& operator-=(const quantity<R2, Rep2>& q) &
|
constexpr quantity_point& operator-=(const quantity<R2, Rep2>& q) &
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user