Skip to content

Commit

Permalink
refactor: expr_fractions takes direct OneType type now instead of…
Browse files Browse the repository at this point in the history
… a trait
  • Loading branch information
mpusz committed Oct 27, 2024
1 parent 76057ea commit 0454107
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 33 deletions.
12 changes: 1 addition & 11 deletions src/core/include/mp-units/framework/dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ MP_UNITS_EXPORT struct dimension_one;

namespace detail {

template<typename T>
struct is_dimension_one : std::false_type {};

template<typename Lhs, typename Rhs>
struct base_dimension_less : std::bool_constant<type_name<Lhs>() < type_name<Rhs>()> {};

template<typename T1, typename T2>
using type_list_of_base_dimension_less = expr_less<T1, T2, base_dimension_less>;

template<typename... Expr>
struct derived_dimension_impl : expr_fractions<is_dimension_one, Expr...> {};
struct derived_dimension_impl : expr_fractions<dimension_one, Expr...> {};

struct dimension_interface {
template<Dimension Lhs, Dimension Rhs>
Expand Down Expand Up @@ -183,13 +180,6 @@ MP_UNITS_EXPORT inline constexpr struct dimension_one final :
detail::derived_dimension_impl<> {
} dimension_one;

namespace detail {

template<>
struct is_dimension_one<struct dimension_one> : std::true_type {};

} // namespace detail

MP_UNITS_EXPORT_BEGIN

[[nodiscard]] consteval Dimension auto inverse(Dimension auto d) { return dimension_one / d; }
Expand Down
6 changes: 3 additions & 3 deletions src/core/include/mp-units/framework/expression_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ struct expr_fractions_result {
using _den_ = Den; // exposition only
};

template<template<typename> typename OneType, typename List>
template<typename OneType, typename List>
[[nodiscard]] consteval auto expr_fractions_impl()
{
constexpr std::size_t size = type_list_size<List>;
Expand All @@ -307,7 +307,7 @@ template<template<typename> typename OneType, typename List>
using last_element = type_list_back<List>;

if constexpr (is_specialization_of<last_element, per>) {
if constexpr (size == 2 && OneType<type_list_front<List>>::value)
if constexpr (size == 2 && is_same_v<type_list_front<List>, OneType>)
return expr_fractions_result<type_list<>, type_list_map<last_element, type_list>>{};
else {
using split = type_list_split<List, size - 1>;
Expand All @@ -322,7 +322,7 @@ template<template<typename> typename OneType, typename List>
/**
* @brief Divides expression template spec to numerator and denominator parts
*/
template<template<typename> typename OneType, typename... Ts>
template<typename OneType, typename... Ts>
struct expr_fractions : decltype(expr_fractions_impl<OneType, type_list<Ts...>>()) {};

// expr_make_spec
Expand Down
14 changes: 2 additions & 12 deletions src/core/include/mp-units/framework/quantity_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,16 @@ struct quantity_spec<Self, QS, Eq, Args...> : detail::quantity_spec_interface<Se

namespace detail {

template<typename T>
struct is_dimensionless : std::false_type {};

template<typename... Expr>
struct derived_quantity_spec_impl :
#if MP_UNITS_API_NO_CRTP
detail::quantity_spec_interface,
#else
detail::quantity_spec_interface<derived_quantity_spec<Expr...>>,
#endif
detail::expr_fractions<detail::is_dimensionless, Expr...> {
detail::expr_fractions<dimensionless, Expr...> {
using _base_type_ = derived_quantity_spec_impl;
using _base_ = detail::expr_fractions<detail::is_dimensionless, Expr...>;
using _base_ = detail::expr_fractions<dimensionless, Expr...>;

static constexpr Dimension auto dimension =
detail::expr_map<detail::to_dimension, derived_dimension, struct dimension_one,
Expand Down Expand Up @@ -506,13 +503,6 @@ struct derived_quantity_spec final : detail::derived_quantity_spec_impl<Expr...>
*/
MP_UNITS_EXPORT QUANTITY_SPEC(dimensionless, derived_quantity_spec<>{});

namespace detail {

template<>
struct is_dimensionless<struct dimensionless> : std::true_type {};

} // namespace detail

/**
* @brief Quantity kind specifier
*
Expand Down
8 changes: 1 addition & 7 deletions src/core/include/mp-units/framework/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,8 @@ struct common_unit final : decltype(detail::get_common_scaled_unit(U1{}, U2{}, R

namespace detail {

template<typename T>
struct is_one : std::false_type {};

template<typename... Expr>
struct derived_unit_impl : detail::unit_interface, detail::expr_fractions<detail::is_one, Expr...> {
struct derived_unit_impl : detail::unit_interface, detail::expr_fractions<one, Expr...> {
using _base_type_ = derived_unit_impl; // exposition only
};

Expand Down Expand Up @@ -530,9 +527,6 @@ MP_UNITS_EXPORT inline constexpr struct one final : detail::derived_unit_impl<>

namespace detail {

template<>
struct is_one<struct one> : std::true_type {};

template<Unit T, auto M, typename U>
[[nodiscard]] consteval auto get_canonical_unit_impl(T, const scaled_unit_impl<M, U>&)
{
Expand Down

0 comments on commit 0454107

Please sign in to comment.