refactor: ♻️ exp_* operations on exponents renamed to `exponent_*

This commit is contained in:
Mateusz Pusz committed 2020-09-08 11:10:33 +02:00
1 parent 563b358d5e
commit 7ed4f19ef3
15 files changed
+85 -85

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ constexpr ratio exp_ratio()
* @brief Calculates the common ratio of all the references of base units in the derived dimension
*/
template<typename... Es>
constexpr ratio base_units_ratio(exp_list<Es...>)
constexpr ratio base_units_ratio(exponent_list<Es...>)
{
return (exp_ratio<Es>() * ... * ratio(1));
}
+1 -1
View File
@@ -80,7 +80,7 @@ template<typename... Es>
inline constexpr int negative_exp_count = ((Es::num < 0 ? 1 : 0) + ... + 0);
template<typename... Us, typename... Es, std::size_t... Idxs>
constexpr auto deduced_symbol_text(exp_list<Es...>, std::index_sequence<Idxs...>)
constexpr auto deduced_symbol_text(exponent_list<Es...>, std::index_sequence<Idxs...>)
{
constexpr auto neg_exp = negative_exp_count<Es...>;
return (exp_text<Es, Us::symbol, neg_exp, Idxs>() + ...);
+2 -2
View File
@@ -31,7 +31,7 @@ template<typename ExpList, Unit... Us>
inline constexpr bool same_scaled_units = false;
template<typename... Es, Unit... Us>
inline constexpr bool same_scaled_units<exp_list<Es...>, Us...> = (UnitOf<Us, typename Es::dimension> && ...);
inline constexpr bool same_scaled_units<exponent_list<Es...>, Us...> = (UnitOf<Us, typename Es::dimension> && ...);
// deduced_unit
@@ -45,7 +45,7 @@ constexpr ratio inverse_if_negative(const ratio& r)
}
template<Unit... Us, typename... Es>
constexpr ratio derived_ratio(exp_list<Es...>)
constexpr ratio derived_ratio(exponent_list<Es...>)
{
return (... * inverse_if_negative<Es>(pow<detail::abs(Es::num)>(Us::ratio) / dimension_unit<typename Es::dimension>::ratio));
}
@@ -46,14 +46,14 @@ namespace units::detail {
template<Exponent... Es>
requires (BaseDimension<typename Es::dimension> && ...)
struct derived_dimension_base : downcast_base<derived_dimension_base<Es...>> {
using exponents = exp_list<Es...>;
using exponents = exponent_list<Es...>;
};
template<typename T>
struct to_derived_dimension_base;
template<Exponent... Es>
struct to_derived_dimension_base<exp_list<Es...>> {
struct to_derived_dimension_base<exponent_list<Es...>> {
using type = derived_dimension_base<Es...>;
};
+9 -9
View File
@@ -40,28 +40,28 @@ template<typename ExpList>
struct dim_consolidate;
template<>
struct dim_consolidate<exp_list<>> {
using type = exp_list<>;
struct dim_consolidate<exponent_list<>> {
using type = exponent_list<>;
};
template<typename E>
struct dim_consolidate<exp_list<E>> {
using type = exp_list<E>;
struct dim_consolidate<exponent_list<E>> {
using type = exponent_list<E>;
};
template<typename E1, typename... ERest>
struct dim_consolidate<exp_list<E1, ERest...>> {
using type = type_list_push_front<typename dim_consolidate<exp_list<ERest...>>::type, E1>;
struct dim_consolidate<exponent_list<E1, ERest...>> {
using type = type_list_push_front<typename dim_consolidate<exponent_list<ERest...>>::type, E1>;
};
template<BaseDimension Dim, std::intmax_t Num1, std::intmax_t Den1, std::intmax_t Num2, std::intmax_t Den2, typename... ERest>
struct dim_consolidate<exp_list<exponent<Dim, Num1, Den1>, exponent<Dim, Num2, Den2>, ERest...>> {
struct dim_consolidate<exponent_list<exponent<Dim, Num1, Den1>, exponent<Dim, Num2, Den2>, ERest...>> {
// TODO: we have ration_add now, but dim_consolidate etc, now need to cope with our new ratio
using r1 = std::ratio<Num1, Den1>;
using r2 = std::ratio<Num2, Den2>;
using r = std::ratio_add<r1, r2>;
using type = conditional<r::num == 0, typename dim_consolidate<exp_list<ERest...>>::type,
typename dim_consolidate<exp_list<exponent<Dim, r::num, r::den>, ERest...>>::type>;
using type = conditional<r::num == 0, typename dim_consolidate<exponent_list<ERest...>>::type,
typename dim_consolidate<exponent_list<exponent<Dim, r::num, r::den>, ERest...>>::type>;
};
} // namespace units::detail
+2 -2
View File
@@ -38,7 +38,7 @@ struct dim_unpack;
template<>
struct dim_unpack<> {
using type = exp_list<>;
using type = exponent_list<>;
};
template<BaseDimension Dim, std::intmax_t Num, std::intmax_t Den, Exponent... ERest>
@@ -53,7 +53,7 @@ struct dim_unpack<exponent<Dim, Num, Den>, ERest...> {
template<Exponent... Es, std::intmax_t Num, std::intmax_t Den, Exponent... ERest>
struct dim_unpack<exponent<derived_dimension_base<Es...>, Num, Den>, ERest...> {
using type = type_list_push_front<typename dim_unpack<ERest...>::type, exp_multiply<Es, Num, Den>...>;
using type = type_list_push_front<typename dim_unpack<ERest...>::type, exponent_multiply<Es, Num, Den>...>;
};
} // namespace units::detail
+6 -6
View File
@@ -122,7 +122,7 @@ struct dim_invert_impl<derived_dimension_base<exponent<D, -1>>> {
template<typename... Es>
struct dim_invert_impl<derived_dimension_base<Es...>> {
using type = downcast_dimension<derived_dimension_base<exp_invert<Es>...>>;
using type = downcast_dimension<derived_dimension_base<exponent_invert<Es>...>>;
};
template<DerivedDimension D>
@@ -141,12 +141,12 @@ template<typename T>
struct to_dimension;
template<Exponent... Es>
struct to_dimension<exp_list<Es...>> {
struct to_dimension<exponent_list<Es...>> {
using type = derived_dimension_base<Es...>;
};
template<BaseDimension D>
struct to_dimension<exp_list<exponent<D, 1>>> {
struct to_dimension<exponent_list<exponent<D, 1>>> {
using type = D;
};
@@ -160,7 +160,7 @@ struct to_dimension<exp_list<exponent<D, 1>>> {
* dimension itself.
*/
template<Dimension D1, Dimension D2>
using merge_dimension = TYPENAME to_dimension<typename dim_consolidate<type_list_merge_sorted<typename D1::exponents, typename D2::exponents, exp_less>>::type>::type;
using merge_dimension = TYPENAME to_dimension<typename dim_consolidate<type_list_merge_sorted<typename D1::exponents, typename D2::exponents, exponent_less>>::type>::type;
template<Dimension D1, Dimension D2>
struct dimension_multiply_impl;
@@ -216,7 +216,7 @@ struct dimension_sqrt_impl<D> {
template<typename... Es>
struct dimension_sqrt_impl<derived_dimension_base<Es...>> {
using type = downcast_dimension<derived_dimension_base<exp_multiply<Es, 1, 2>...>>;
using type = downcast_dimension<derived_dimension_base<exponent_multiply<Es, 1, 2>...>>;
};
} // namespace detail
@@ -252,7 +252,7 @@ struct dimension_pow_impl<D, N> {
template<typename... Es, std::intmax_t N>
struct dimension_pow_impl<derived_dimension_base<Es...>, N> {
using type = downcast_dimension<derived_dimension_base<exp_multiply<Es, N, 1>...>>;
using type = downcast_dimension<derived_dimension_base<exponent_multiply<Es, N, 1>...>>;
};
} // namespace detail
+10 -10
View File
@@ -103,40 +103,40 @@ constexpr auto prefix_or_ratio_text()
}
template<typename... Es, std::size_t... Idxs>
constexpr auto derived_dimension_unit_text(exp_list<Es...>, std::index_sequence<Idxs...>)
constexpr auto derived_dimension_unit_text(exponent_list<Es...>, std::index_sequence<Idxs...>)
{
return (exp_text<Es, dimension_unit<typename Es::dimension>::symbol, negative_exp_count<Es...>, Idxs>() + ... + basic_symbol_text(basic_fixed_string("")));
}
template<typename... Es>
constexpr auto derived_dimension_unit_text(exp_list<Es...> list)
constexpr auto derived_dimension_unit_text(exponent_list<Es...> list)
{
return derived_dimension_unit_text(list, std::index_sequence_for<Es...>());
}
template<Exponent... Es>
constexpr auto exp_list_with_named_units(exp_list<Es...>);
constexpr auto exponent_list_with_named_units(exponent_list<Es...>);
template<Exponent Exp>
constexpr auto exp_list_with_named_units(Exp)
constexpr auto exponent_list_with_named_units(Exp)
{
using dim = TYPENAME Exp::dimension;
if constexpr(dimension_unit<dim>::is_named) {
return exp_list<Exp>();
return exponent_list<Exp>();
}
else {
using recipe = TYPENAME dim::recipe;
return exp_list_with_named_units(recipe());
return exponent_list_with_named_units(recipe());
}
}
template<Exponent... Es>
constexpr auto exp_list_with_named_units(exp_list<Es...>)
constexpr auto exponent_list_with_named_units(exponent_list<Es...>)
{
return type_list_join<decltype(exp_list_with_named_units(Es()))...>();
return type_list_join<decltype(exponent_list_with_named_units(Es()))...>();
}
constexpr auto exp_list_with_named_units(exp_list<> empty)
constexpr auto exponent_list_with_named_units(exponent_list<> empty)
{
return empty;
}
@@ -145,7 +145,7 @@ template<Dimension Dim>
constexpr auto derived_dimension_unit_text()
{
using recipe = TYPENAME Dim::recipe;
return derived_dimension_unit_text(exp_list_with_named_units(recipe()));
return derived_dimension_unit_text(exponent_list_with_named_units(recipe()));
}
// TODO Inline below concept when switched to gcc-10