mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 13:14:29 +02:00
refactor: quantity_point
compile-time optimizations
This commit is contained in:
@@ -116,7 +116,7 @@ public:
|
|||||||
requires std::constructible_from<quantity_type, typename QP::quantity_type>
|
requires std::constructible_from<quantity_type, typename QP::quantity_type>
|
||||||
constexpr explicit(!std::convertible_to<typename QP::quantity_type, quantity_type>) quantity_point(const QP& qp) :
|
constexpr explicit(!std::convertible_to<typename QP::quantity_type, quantity_type>) quantity_point(const QP& qp) :
|
||||||
q_([&] {
|
q_([&] {
|
||||||
if constexpr (std::is_same_v<std::remove_const_t<decltype(point_origin)>,
|
if constexpr (is_same_v<std::remove_const_t<decltype(point_origin)>,
|
||||||
std::remove_const_t<decltype(QP::point_origin)>>) {
|
std::remove_const_t<decltype(QP::point_origin)>>) {
|
||||||
return qp.relative();
|
return qp.relative();
|
||||||
} else if constexpr (detail::is_derived_from_specialization_of_relative_point_origin<
|
} else if constexpr (detail::is_derived_from_specialization_of_relative_point_origin<
|
||||||
@@ -144,7 +144,7 @@ public:
|
|||||||
template<PointOriginFor<quantity_spec> NewPO>
|
template<PointOriginFor<quantity_spec> NewPO>
|
||||||
[[nodiscard]] constexpr QuantityPointOf<NewPO{}> auto point_from(NewPO origin) const
|
[[nodiscard]] constexpr QuantityPointOf<NewPO{}> auto point_from(NewPO origin) const
|
||||||
{
|
{
|
||||||
if constexpr (std::is_same_v<NewPO, std::remove_const_t<decltype(point_origin)>>) {
|
if constexpr (is_same_v<NewPO, std::remove_const_t<decltype(point_origin)>>) {
|
||||||
return *this;
|
return *this;
|
||||||
} else if constexpr (detail::is_derived_from_specialization_of_relative_point_origin<NewPO>) {
|
} else if constexpr (detail::is_derived_from_specialization_of_relative_point_origin<NewPO>) {
|
||||||
auto q = absolute() - origin.quantity_point.absolute();
|
auto q = absolute() - origin.quantity_point.absolute();
|
||||||
@@ -276,6 +276,10 @@ template<QuantityPoint QP1, QuantityPointOf<QP1::absolute_point_origin> QP2>
|
|||||||
[[nodiscard]] constexpr Quantity auto operator-(const QP1& lhs, const QP2& rhs)
|
[[nodiscard]] constexpr Quantity auto operator-(const QP1& lhs, const QP2& rhs)
|
||||||
requires requires { lhs.absolute() - rhs.absolute(); }
|
requires requires { lhs.absolute() - rhs.absolute(); }
|
||||||
{
|
{
|
||||||
|
if constexpr (is_same_v<std::remove_const_t<decltype(QP1::point_origin)>,
|
||||||
|
std::remove_const_t<decltype(QP2::point_origin)>>)
|
||||||
|
return lhs.relative() - rhs.relative();
|
||||||
|
else
|
||||||
return lhs.absolute() - rhs.absolute();
|
return lhs.absolute() - rhs.absolute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,6 +287,10 @@ template<QuantityPoint QP1, QuantityPointOf<QP1::absolute_point_origin> QP2>
|
|||||||
requires std::three_way_comparable_with<typename QP1::quantity_type, typename QP2::quantity_type>
|
requires std::three_way_comparable_with<typename QP1::quantity_type, typename QP2::quantity_type>
|
||||||
[[nodiscard]] constexpr auto operator<=>(const QP1& lhs, const QP2& rhs)
|
[[nodiscard]] constexpr auto operator<=>(const QP1& lhs, const QP2& rhs)
|
||||||
{
|
{
|
||||||
|
if constexpr (is_same_v<std::remove_const_t<decltype(QP1::point_origin)>,
|
||||||
|
std::remove_const_t<decltype(QP2::point_origin)>>)
|
||||||
|
return lhs.relative() <=> rhs.relative();
|
||||||
|
else
|
||||||
return lhs.absolute() <=> rhs.absolute();
|
return lhs.absolute() <=> rhs.absolute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,6 +298,10 @@ template<QuantityPoint QP1, QuantityPointOf<QP1::absolute_point_origin> QP2>
|
|||||||
requires std::equality_comparable_with<typename QP1::quantity_type, typename QP2::quantity_type>
|
requires std::equality_comparable_with<typename QP1::quantity_type, typename QP2::quantity_type>
|
||||||
[[nodiscard]] constexpr bool operator==(const QP1& lhs, const QP2& rhs)
|
[[nodiscard]] constexpr bool operator==(const QP1& lhs, const QP2& rhs)
|
||||||
{
|
{
|
||||||
|
if constexpr (is_same_v<std::remove_const_t<decltype(QP1::point_origin)>,
|
||||||
|
std::remove_const_t<decltype(QP2::point_origin)>>)
|
||||||
|
return lhs.relative() == rhs.relative();
|
||||||
|
else
|
||||||
return lhs.absolute() == rhs.absolute();
|
return lhs.absolute() == rhs.absolute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user