refactor: dimensions design cleanup
This commit is contained in:
1 parent
3194d45b08
commit
6e8ca72678
6 files changed
+133
-55
No files matched your search
@@ -104,19 +104,41 @@ using type_list_of_base_dimension_less = expr_less<T1, T2, base_dimension_less>;
|
||||
template<typename T>
|
||||
inline constexpr bool is_one_dim = false;
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_power_of_dim =
|
||||
requires {
|
||||
requires is_specialization_of_power<T> && (BaseDimension<typename T::factor> || is_one_dim<typename T::factor>);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_per_of_dims = false;
|
||||
|
||||
template<typename... Ts>
|
||||
inline constexpr bool is_per_of_dims<per<Ts...>> =
|
||||
(... && (BaseDimension<Ts> || is_one_dim<Ts> || is_power_of_dim<Ts>));
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// TODO add checking for `per` and power elements as well
|
||||
template<typename T>
|
||||
concept DimensionSpec =
|
||||
BaseDimension<T> || detail::is_one_dim<T> || is_specialization_of<T, per> || detail::is_specialization_of_power<T>;
|
||||
BaseDimension<T> || detail::is_one_dim<T> || detail::is_power_of_dim<T> || detail::is_per_of_dims<T>;
|
||||
|
||||
template<DimensionSpec... Ds>
|
||||
struct derived_dimension;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename... Ds>
|
||||
struct derived_dimension_impl : detail::expr_fractions<derived_dimension<>, Ds...> {
|
||||
using _type_ = derived_dimension<Ds...>; // exposition only
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// User should not instantiate this type!!!
|
||||
// It should not be exported from the module
|
||||
template<DimensionSpec... Ds>
|
||||
struct derived_dimension : detail::expr_fractions<derived_dimension<>, Ds...> {
|
||||
using type = derived_dimension<Ds...>;
|
||||
};
|
||||
struct derived_dimension : detail::derived_dimension_impl<Ds...> {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
@@ -154,7 +176,7 @@ struct dim_type_impl {
|
||||
|
||||
template<DerivedDimension T>
|
||||
struct dim_type_impl<T> {
|
||||
using type = T::type;
|
||||
using type = T::_type_;
|
||||
};
|
||||
|
||||
template<Dimension T>
|
||||
@@ -189,11 +211,11 @@ template<Dimension D1, Dimension D2>
|
||||
return is_same_v<D1, D2>;
|
||||
}
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] consteval bool equivalent(D1, D2)
|
||||
{
|
||||
return is_same_v<detail::dim_type<D1>, detail::dim_type<D2>>;
|
||||
}
|
||||
// template<Dimension D1, Dimension D2>
|
||||
// [[nodiscard]] consteval bool equivalent(D1, D2)
|
||||
// {
|
||||
// return is_same_v<detail::dim_type<D1>, detail::dim_type<D2>>;
|
||||
// }
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] consteval bool convertible(D1, D2)
|
||||
|
||||
@@ -514,15 +514,12 @@ inline constexpr struct mag_pi : magnitude<std::numbers::pi_v<long double>> {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Magnitude equality implementation.
|
||||
|
||||
// template<auto... LeftBPs, auto... RightBPs>
|
||||
// constexpr bool operator==(magnitude<LeftBPs...>, magnitude<RightBPs...>)
|
||||
// {
|
||||
// if constexpr (sizeof...(LeftBPs) == sizeof...(RightBPs)) {
|
||||
// return ((LeftBPs == RightBPs) && ...);
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
template<Magnitude M1, Magnitude M2>
|
||||
[[nodiscard]] consteval bool operator==(M1, M2)
|
||||
{
|
||||
return std::is_same_v<M1, M2>;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Magnitude rational powers implementation.
|
||||
|
||||
@@ -69,8 +69,8 @@ concept harmonic_ = // exposition only
|
||||
|
||||
template<typename QFrom, typename QTo>
|
||||
concept quantity_convertible_to_ = // exposition only
|
||||
Quantity<QFrom> && Quantity<QTo> && convertible(QFrom::dimension, QTo::dimension) &&
|
||||
convertible(QFrom::unit, QTo::unit) && scalable_with_<typename QFrom::rep, typename QTo::rep> &&
|
||||
Quantity<QFrom> && Quantity<QTo> &&
|
||||
convertible(QFrom::reference, QTo::reference) && scalable_with_<typename QFrom::rep, typename QTo::rep> &&
|
||||
(floating_point_<QTo> || (!floating_point_<QFrom> && harmonic_<QFrom, QTo>));
|
||||
|
||||
template<typename Func, typename T, typename U>
|
||||
|
||||
@@ -99,11 +99,10 @@ namespace detail {
|
||||
* @tparam To a target quantity type to cast to
|
||||
*/
|
||||
template<Quantity To, auto R, scalable_with_<typename To::rep> Rep>
|
||||
requires(convertible(R, To::reference))
|
||||
requires(convertible(To::reference, R))
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<R, Rep>& q)
|
||||
{
|
||||
// TODO implement same unit magnitude check
|
||||
if constexpr (std::same_as<decltype(R.unit), decltype(To::unit)>) {
|
||||
if constexpr (R.unit == To::unit) {
|
||||
return To(static_cast<TYPENAME To::rep>(q.number()));
|
||||
} else {
|
||||
// using traits = detail::cast_traits<Rep, typename To::rep>;
|
||||
@@ -202,7 +201,7 @@ template<Representation ToRep, auto R, scalable_with_<ToRep> Rep>
|
||||
// requires(std::constructible_from<ToRep, std::common_type_t<ToRep, Rep>>)
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<R, Rep>& q)
|
||||
{
|
||||
return To(static_cast<ToRep>(q.number()));
|
||||
return quantity_cast<quantity<R, ToRep>>(q);
|
||||
}
|
||||
|
||||
// /**
|
||||
|
||||
@@ -136,11 +136,11 @@ template<Representation Rep, Reference R>
|
||||
|
||||
void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, Reference auto) = delete;
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] consteval bool equivalent(R1, R2)
|
||||
{
|
||||
return equivalent(R1::dimension, R2::dimension) && equivalent(R1::unit, R2::unit);
|
||||
}
|
||||
// template<Reference R1, Reference R2>
|
||||
// [[nodiscard]] consteval bool equivalent(R1, R2)
|
||||
// {
|
||||
// return equivalent(R1::dimension, R2::dimension) && R1::unit == R2::unit;
|
||||
// }
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] consteval bool convertible(R1, R2)
|
||||
@@ -148,6 +148,12 @@ template<Reference R1, Reference R2>
|
||||
return convertible(R1::dimension, R2::dimension) && convertible(R1::unit, R2::unit);
|
||||
}
|
||||
|
||||
// template<Reference R1, Reference R2>
|
||||
// [[nodiscard]] consteval bool castable(R1, R2)
|
||||
// {
|
||||
// return equivalent(R1::dimension, R2::dimension) && convertible(R1::unit, R2::unit);
|
||||
// }
|
||||
|
||||
|
||||
template<Dimension auto Dim, Unit auto CoU>
|
||||
struct system_reference {
|
||||
|
||||
Reference in new issue
Block a user