Skip to content

Commit

Permalink
refactor: power members refactored to be explicitly exposition only
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Nov 26, 2024
1 parent b77aa52 commit 360cf7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/core/include/mp-units/framework/expression_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ constexpr bool ratio_one<N, N> = true;
template<detail::SymbolicArg F, int Num, int... Den>
requires(detail::valid_ratio<Num, Den...> && detail::positive_ratio<Num, Den...> && !detail::ratio_one<Num, Den...>)
struct power final {
using factor = F;
static constexpr detail::ratio exponent{Num, Den...};
using _factor_ = F;
static constexpr detail::ratio _exponent_{Num, Den...};
};

namespace detail {
Expand Down Expand Up @@ -146,7 +146,7 @@ template<SymbolicArg T, ratio R>
consteval auto power_or_T_impl()
{
if constexpr (is_specialization_of_power<T>) {
return power_or_T_impl<typename T::factor, T::exponent * R>();
return power_or_T_impl<typename T::_factor_, T::_exponent_ * R>();
} else {
if constexpr (R.den == 1) {
if constexpr (R.num == 1)
Expand Down Expand Up @@ -198,13 +198,13 @@ struct expr_consolidate_impl<type_list<T, T, Rest...>> {
// replaces the instance of a type and a power of it with one with incremented power
template<typename T, int... Ints, typename... Rest>
struct expr_consolidate_impl<type_list<T, power<T, Ints...>, Rest...>> {
using type = expr_consolidate_impl<type_list<power_or_T<T, power<T, Ints...>::exponent + 1>, Rest...>>::type;
using type = expr_consolidate_impl<type_list<power_or_T<T, power<T, Ints...>::_exponent_ + 1>, Rest...>>::type;
};

// accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`)
template<typename T, int... Ints1, int... Ints2, typename... Rest>
struct expr_consolidate_impl<type_list<power<T, Ints1...>, power<T, Ints2...>, Rest...>> {
static constexpr ratio r = power<T, Ints1...>::exponent + power<T, Ints2...>::exponent;
static constexpr ratio r = power<T, Ints1...>::_exponent_ + power<T, Ints2...>::_exponent_;
using type = expr_consolidate_impl<type_list<power_or_T<T, r>, Rest...>>::type;
};

Expand Down Expand Up @@ -260,7 +260,7 @@ struct expr_simplify_power {
template<typename T, typename... NRest, int... Ints, typename... DRest, template<typename, typename> typename Pred>
struct expr_simplify<type_list<power<T, Ints...>, NRest...>, type_list<T, DRest...>, Pred> {
using impl = expr_simplify<type_list<NRest...>, type_list<DRest...>, Pred>;
using type = expr_simplify_power<T, power<T, Ints...>::exponent, ratio{1}>;
using type = expr_simplify_power<T, power<T, Ints...>::_exponent_, ratio{1}>;
using num = type_list_join<typename type::num, typename impl::num>;
using den = type_list_join<typename type::den, typename impl::den>;
};
Expand All @@ -269,7 +269,7 @@ struct expr_simplify<type_list<power<T, Ints...>, NRest...>, type_list<T, DRest.
template<typename T, typename... NRest, typename... DRest, int... Ints, template<typename, typename> typename Pred>
struct expr_simplify<type_list<T, NRest...>, type_list<power<T, Ints...>, DRest...>, Pred> {
using impl = expr_simplify<type_list<NRest...>, type_list<DRest...>, Pred>;
using type = expr_simplify_power<T, ratio{1}, power<T, Ints...>::exponent>;
using type = expr_simplify_power<T, ratio{1}, power<T, Ints...>::_exponent_>;
using num = type_list_join<typename type::num, typename impl::num>;
using den = type_list_join<typename type::den, typename impl::den>;
};
Expand All @@ -280,7 +280,7 @@ template<typename T, typename... NRest, int... Ints1, typename... DRest, int...
requires(!std::same_as<power<T, Ints1...>, power<T, Ints2...>>)
struct expr_simplify<type_list<power<T, Ints1...>, NRest...>, type_list<power<T, Ints2...>, DRest...>, Pred> {
using impl = expr_simplify<type_list<NRest...>, type_list<DRest...>, Pred>;
using type = expr_simplify_power<T, power<T, Ints1...>::exponent, power<T, Ints2...>::exponent>;
using type = expr_simplify_power<T, power<T, Ints1...>::_exponent_, power<T, Ints2...>::_exponent_>;
using num = type_list_join<typename type::num, typename impl::num>;
using den = type_list_join<typename type::den, typename impl::den>;
};
Expand Down
6 changes: 3 additions & 3 deletions src/core/include/mp-units/framework/quantity_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ template<QuantitySpec Q, int... Ints>
requires requires { Q::_equation_; }
[[nodiscard]] consteval auto explode_to_equation(power<Q, Ints...>)
{
constexpr ratio exp = power<Q, Ints...>::exponent;
constexpr ratio exp = power<Q, Ints...>::_exponent_;
return explode_to_equation_result{
pow<exp.num, exp.den>(Q::_equation_),
defines_equation(Q{}) ? specs_convertible_result::yes : specs_convertible_result::explicit_conversion};
Expand Down Expand Up @@ -917,13 +917,13 @@ template<typename From, typename To>
constexpr auto qto = map_power(To{});
if constexpr (get_kind_tree_root(qfrom) == get_kind_tree_root(qto)) {
if constexpr (is_specialization_of_power<From> && is_specialization_of_power<To>)
return extract_results{true, typename From::factor{}, typename To::factor{}, prepend_rest::no};
return extract_results{true, typename From::_factor_{}, typename To::_factor_{}, prepend_rest::no};
else
return extract_results{true, qfrom, qto, prepend_rest::no};
} else {
auto normalize = []<typename Q>(Q) {
if constexpr (is_specialization_of_power<Q>)
return std::tuple{typename Q::factor{}, Q::exponent};
return std::tuple{typename Q::_factor_{}, Q::_exponent_};
else
return std::tuple{Q{}, ratio{1}};
};
Expand Down

0 comments on commit 360cf7d

Please sign in to comment.