mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 03:44:27 +02:00
refactor: expr_fractions
takes direct OneType
type now instead of a trait
This commit is contained in:
@@ -59,9 +59,6 @@ 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>()> {};
|
||||
|
||||
@@ -69,7 +66,7 @@ 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>
|
||||
@@ -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; }
|
||||
|
@@ -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>;
|
||||
@@ -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>;
|
||||
@@ -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
|
||||
|
@@ -429,9 +429,6 @@ 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
|
||||
@@ -439,9 +436,9 @@ struct derived_quantity_spec_impl :
|
||||
#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,
|
||||
@@ -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
|
||||
*
|
||||
|
@@ -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
|
||||
};
|
||||
|
||||
@@ -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>&)
|
||||
{
|
||||
|
Reference in New Issue
Block a user