refactor: 💥 from now on point origins must be marked final + absolute_point_origin does not use CRTP anymore
This commit is contained in:
1 parent
bd6b1e654d
commit
05fc1e29c8
15 files changed
+93
-97
No files matched your search
@@ -35,11 +35,10 @@
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
MP_UNITS_EXPORT template<typename Derived, QuantitySpec auto QS>
|
||||
MP_UNITS_EXPORT template<QuantitySpec auto QS>
|
||||
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
|
||||
struct absolute_point_origin {
|
||||
static constexpr QuantitySpec auto quantity_spec = QS;
|
||||
using _type_ = absolute_point_origin;
|
||||
};
|
||||
|
||||
MP_UNITS_EXPORT template<QuantityPoint auto QP>
|
||||
@@ -56,7 +55,7 @@ struct relative_point_origin {
|
||||
};
|
||||
|
||||
template<QuantitySpec auto QS>
|
||||
struct zeroth_point_origin_ : absolute_point_origin<zeroth_point_origin_<QS>, QS> {};
|
||||
struct zeroth_point_origin_ final : absolute_point_origin<QS> {};
|
||||
|
||||
MP_UNITS_EXPORT template<QuantitySpec auto QS>
|
||||
inline constexpr zeroth_point_origin_<QS> zeroth_point_origin;
|
||||
@@ -81,9 +80,8 @@ MP_UNITS_EXPORT template<PointOrigin PO1, PointOrigin PO2>
|
||||
[[nodiscard]] consteval bool operator==(PO1 po1, PO2 po2)
|
||||
{
|
||||
if constexpr (detail::AbsolutePointOrigin<PO1> && detail::AbsolutePointOrigin<PO2>)
|
||||
return is_same_v<typename PO1::_type_, typename PO2::_type_> ||
|
||||
(detail::is_zeroth_point_origin(po1) && detail::is_zeroth_point_origin(po2) &&
|
||||
interconvertible(po1.quantity_spec, po2.quantity_spec));
|
||||
return is_same_v<PO1, PO2> || (detail::is_zeroth_point_origin(po1) && detail::is_zeroth_point_origin(po2) &&
|
||||
interconvertible(po1.quantity_spec, po2.quantity_spec));
|
||||
else if constexpr (detail::RelativePointOrigin<PO1> && detail::RelativePointOrigin<PO2>)
|
||||
return PO1::quantity_point == PO2::quantity_point;
|
||||
else if constexpr (detail::RelativePointOrigin<PO1>)
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
MP_UNITS_EXPORT template<typename Derived, QuantitySpec auto QS>
|
||||
MP_UNITS_EXPORT template<QuantitySpec auto QS>
|
||||
struct absolute_point_origin;
|
||||
|
||||
namespace detail {
|
||||
@@ -40,22 +40,15 @@ namespace detail {
|
||||
template<typename T>
|
||||
inline constexpr bool is_quantity_point = false;
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_specialization_of_absolute_point_origin = false;
|
||||
|
||||
template<typename D, auto Q>
|
||||
inline constexpr bool is_specialization_of_absolute_point_origin<absolute_point_origin<D, Q>> = true;
|
||||
|
||||
template<typename D, auto Q>
|
||||
void to_base_specialization_of_absolute_point_origin(const volatile absolute_point_origin<D, Q>*);
|
||||
template<auto Q>
|
||||
void to_base_specialization_of_absolute_point_origin(const volatile absolute_point_origin<Q>*);
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_derived_from_specialization_of_absolute_point_origin =
|
||||
requires(T* t) { to_base_specialization_of_absolute_point_origin(t); };
|
||||
|
||||
template<typename T>
|
||||
concept AbsolutePointOrigin =
|
||||
is_derived_from_specialization_of_absolute_point_origin<T> && !is_specialization_of_absolute_point_origin<T>;
|
||||
concept AbsolutePointOrigin = is_derived_from_specialization_of_absolute_point_origin<T> && std::is_final_v<T>;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -72,12 +65,6 @@ struct relative_point_origin;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_specialization_of_relative_point_origin = false;
|
||||
|
||||
template<auto QP>
|
||||
inline constexpr bool is_specialization_of_relative_point_origin<relative_point_origin<QP>> = true;
|
||||
|
||||
template<auto QP>
|
||||
void to_base_specialization_of_relative_point_origin(const volatile relative_point_origin<QP>*);
|
||||
|
||||
@@ -86,8 +73,7 @@ inline constexpr bool is_derived_from_specialization_of_relative_point_origin =
|
||||
requires(T* t) { to_base_specialization_of_relative_point_origin(t); };
|
||||
|
||||
template<typename T>
|
||||
concept RelativePointOrigin =
|
||||
is_derived_from_specialization_of_relative_point_origin<T> && !is_specialization_of_relative_point_origin<T>;
|
||||
concept RelativePointOrigin = is_derived_from_specialization_of_relative_point_origin<T> && std::is_final_v<T>;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ struct quantity_like_traits<std::chrono::duration<Rep, Period>> {
|
||||
};
|
||||
|
||||
template<typename C>
|
||||
struct chrono_point_origin_ : absolute_point_origin<chrono_point_origin_<C>, isq::time> {
|
||||
struct chrono_point_origin_ final : absolute_point_origin<isq::time> {
|
||||
using clock = C;
|
||||
};
|
||||
MP_UNITS_EXPORT template<typename C>
|
||||
|
||||
@@ -44,8 +44,8 @@ inline constexpr struct gram final : named_unit<"g", kind_of<isq::mass>> {} gram
|
||||
inline constexpr auto kilogram = kilo<gram>;
|
||||
inline constexpr struct ampere final : named_unit<"A", kind_of<isq::electric_current>> {} ampere;
|
||||
|
||||
inline constexpr struct absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr struct zeroth_kelvin : decltype(absolute_zero) {} zeroth_kelvin;
|
||||
inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr auto zeroth_kelvin = absolute_zero;
|
||||
inline constexpr struct kelvin final : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;
|
||||
|
||||
inline constexpr struct mole final : named_unit<"mol", kind_of<isq::amount_of_substance>> {} mole;
|
||||
@@ -77,8 +77,8 @@ inline constexpr struct weber final : named_unit<"Wb", volt * second> {} weber;
|
||||
inline constexpr struct tesla final : named_unit<"T", weber / square(metre)> {} tesla;
|
||||
inline constexpr struct henry final : named_unit<"H", weber / ampere> {} henry;
|
||||
|
||||
inline constexpr struct ice_point : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
|
||||
inline constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius;
|
||||
inline constexpr struct ice_point final : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
|
||||
inline constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
inline constexpr struct degree_Celsius final : named_unit<symbol_text{u8"°C", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
|
||||
inline constexpr struct lumen final : named_unit<"lm", candela * steradian> {} lumen;
|
||||
|
||||
@@ -118,7 +118,7 @@ inline constexpr struct troy_pound final : named_unit<"lb t", mag<12> * troy_onc
|
||||
inline constexpr struct inch_of_mercury final : named_unit<"inHg", mag_ratio<3'386'389, 1'000> * si::pascal> {} inch_of_mercury;
|
||||
|
||||
// https://en.wikipedia.org/wiki/United_States_customary_units#Temperature
|
||||
inline constexpr struct zeroth_degree_Fahrenheit : relative_point_origin<quantity_point{-32 * (mag_ratio<5, 9> * si::degree_Celsius)}> {} zeroth_degree_Fahrenheit;
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<quantity_point{-32 * (mag_ratio<5, 9> * si::degree_Celsius)}> {} zeroth_degree_Fahrenheit;
|
||||
inline constexpr struct degree_Fahrenheit final : named_unit<symbol_text{u8"°F", "`F"}, mag_ratio<5, 9> * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit;
|
||||
|
||||
// clang-format on
|
||||
|
||||
Reference in new issue
Block a user