Skip to content

Commit

Permalink
refactor: 💥 quantity_values renamed to representation values
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Nov 26, 2024
1 parent 81e83db commit d6002ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/core/include/mp-units/framework/customization_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ constexpr bool is_tensor = false;
*/
template<typename Rep>
#if MP_UNITS_HOSTED
struct quantity_values : std::chrono::duration_values<Rep> {
struct representation_values : std::chrono::duration_values<Rep> {
#else
struct quantity_values {
struct representation_values {
static constexpr Rep zero() noexcept
requires std::constructible_from<Rep, int>
{
Expand Down Expand Up @@ -120,6 +120,9 @@ struct quantity_values {
}
};

template<typename Rep>
using quantity_values [[deprecated("Use `representation_values` instead")]] = representation_values<Rep>;

/**
* @brief Provides support for external quantity-like types
*
Expand Down
20 changes: 10 additions & 10 deletions src/core/include/mp-units/framework/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,27 @@ class quantity {

// static member functions
[[nodiscard]] static constexpr quantity zero() noexcept
requires requires { quantity_values<rep>::zero(); }
requires requires { representation_values<rep>::zero(); }
{
return {quantity_values<rep>::zero(), R};
return {representation_values<rep>::zero(), R};
}

[[nodiscard]] static constexpr quantity one() noexcept
requires requires { quantity_values<rep>::one(); }
requires requires { representation_values<rep>::one(); }
{
return {quantity_values<rep>::one(), R};
return {representation_values<rep>::one(), R};
}

[[nodiscard]] static constexpr quantity min() noexcept
requires requires { quantity_values<rep>::min(); }
requires requires { representation_values<rep>::min(); }
{
return {quantity_values<rep>::min(), R};
return {representation_values<rep>::min(), R};
}

[[nodiscard]] static constexpr quantity max() noexcept
requires requires { quantity_values<rep>::max(); }
requires requires { representation_values<rep>::max(); }
{
return {quantity_values<rep>::max(), R};
return {representation_values<rep>::max(), R};
}

// construction, assignment, destruction
Expand Down Expand Up @@ -446,7 +446,7 @@ class quantity {
}
friend constexpr decltype(auto) operator/=(Q&& lhs, const Value& val)
{
MP_UNITS_EXPECTS_DEBUG(val != quantity_values<Value>::zero());
MP_UNITS_EXPECTS_DEBUG(val != representation_values<Value>::zero());
// TODO use /= when compiler bug is resolved:
// https://developercommunity.visualstudio.com/t/Discrepancy-in-Behavior-of-operator-an/10732445
lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ / val;
Expand Down Expand Up @@ -577,7 +577,7 @@ class quantity {
(!Reference<Value>) && detail::InvokeResultOf<quantity_spec, std::divides<>, Rep, const Value&>
[[nodiscard]] friend constexpr QuantityOf<quantity_spec> auto operator/(const Q& q, const Value& val)
{
MP_UNITS_EXPECTS_DEBUG(val != quantity_values<Value>::zero());
MP_UNITS_EXPECTS_DEBUG(val != representation_values<Value>::zero());
return ::mp_units::quantity{q.numerical_value_ref_in(unit) / val, R};
}

Expand Down
12 changes: 6 additions & 6 deletions src/core/include/mp-units/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace mp_units {
*/
template<std::intmax_t Num, std::intmax_t Den = 1, auto R, typename Rep>
requires detail::non_zero<Den> && requires(Rep v) {
quantity_values<Rep>::one();
representation_values<Rep>::one();
requires requires { pow(v, 1.0); } || requires { std::pow(v, 1.0); };
}
[[nodiscard]] constexpr quantity<pow<Num, Den>(R), Rep> pow(const quantity<R, Rep>& q) noexcept
Expand Down Expand Up @@ -328,7 +328,7 @@ template<Unit auto To, auto R, typename Rep>
requires((!treat_as_floating_point<Rep>) || requires(Rep v) { floor(v); } || requires(Rep v) { std::floor(v); }) &&
(equivalent(To, get_unit(R)) || requires {
q.force_in(To);
quantity_values<Rep>::one();
representation_values<Rep>::one();
})
{
const auto handle_signed_results = [&]<typename T>(const T& res) {
Expand Down Expand Up @@ -365,7 +365,7 @@ template<Unit auto To, auto R, typename Rep>
requires((!treat_as_floating_point<Rep>) || requires(Rep v) { ceil(v); } || requires(Rep v) { std::ceil(v); }) &&
(equivalent(To, get_unit(R)) || requires {
q.force_in(To);
quantity_values<Rep>::one();
representation_values<Rep>::one();
})
{
const auto handle_signed_results = [&]<typename T>(const T& res) {
Expand Down Expand Up @@ -404,7 +404,7 @@ template<Unit auto To, auto R, typename Rep>
requires((!treat_as_floating_point<Rep>) || requires(Rep v) { round(v); } || requires(Rep v) { std::round(v); }) &&
(equivalent(To, get_unit(R)) || requires {
::mp_units::floor<To>(q);
quantity_values<Rep>::one();
representation_values<Rep>::one();
})
{
if constexpr (equivalent(To, get_unit(R))) {
Expand Down Expand Up @@ -438,11 +438,11 @@ template<Unit auto To, auto R, typename Rep>
template<Unit auto To, auto R, typename Rep>
[[nodiscard]] constexpr QuantityOf<dimensionless / get_quantity_spec(R)> auto inverse(const quantity<R, Rep>& q)
requires requires {
quantity_values<Rep>::one();
representation_values<Rep>::one();
value_cast<To>(1 / q);
}
{
return (quantity_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
return (representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
}

/**
Expand Down

0 comments on commit d6002ce

Please sign in to comment.