Skip to content

Commit

Permalink
refactor: reference now returns explicit types for inverse, pow
Browse files Browse the repository at this point in the history
…, `sqrt`, and `cbrt`
  • Loading branch information
mpusz committed Dec 1, 2024
1 parent e5a2d4b commit e585fd9
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/core/include/mp-units/framework/reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ struct reference {
return {};
}

[[nodiscard]] friend consteval auto inverse(reference) { return detail::reference_t<inverse(Q{}), inverse(U{})>{}; }
[[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(inverse(Q{})),
MP_UNITS_EXPRESSION_WORKAROUND(inverse(U{}))>
inverse(reference)
{
return {};
}

/**
* @brief Computes the value of a reference raised to the `Num/Den` power
Expand All @@ -148,9 +153,11 @@ struct reference {
*/
template<std::intmax_t Num, std::intmax_t Den = 1>
requires detail::non_zero<Den>
[[nodiscard]] friend consteval auto pow(reference)
[[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND((pow<Num, Den>(Q{}))),
MP_UNITS_EXPRESSION_WORKAROUND((pow<Num, Den>(U{})))>
pow(reference)
{
return detail::reference_t<pow<Num, Den>(Q{}), pow<Num, Den>(U{})>{};
return {};
}

/**
Expand All @@ -160,7 +167,12 @@ struct reference {
*
* @return The result of computation
*/
[[nodiscard]] friend consteval auto sqrt(reference) { return detail::reference_t<sqrt(Q{}), sqrt(U{})>{}; }
[[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(sqrt(Q{})),
MP_UNITS_EXPRESSION_WORKAROUND(sqrt(U{}))>
sqrt(reference)
{
return {};
}

/**
* @brief Computes the cubic root of a reference
Expand All @@ -169,7 +181,12 @@ struct reference {
*
* @return The result of computation
*/
[[nodiscard]] friend consteval auto cbrt(reference) { return detail::reference_t<cbrt(Q{}), cbrt(U{})>{}; }
[[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(cbrt(Q{})),
MP_UNITS_EXPRESSION_WORKAROUND(cbrt(U{}))>
cbrt(reference)
{
return {};
}

template<typename Q2, typename U2>
[[nodiscard]] friend consteval bool convertible(reference, reference<Q2, U2>)
Expand Down

0 comments on commit e585fd9

Please sign in to comment.