Skip to content

Commit

Permalink
change implementation of converting constructor of quantity_point fro…
Browse files Browse the repository at this point in the history
…m another QP to leverage sudo_cast
  • Loading branch information
burnpanck committed Jul 20, 2024
1 parent f9ae701 commit 3d4d6fc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/include/mp-units/framework/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@ class quantity_point {
quantity_point(quantity_point&&) = default;
~quantity_point() = default;

// explicit converting constructor from a quantity - only for quantity_points of `default_point_origin`
template<typename Q>
requires QuantityOf<std::remove_cvref_t<Q>, quantity_spec> && std::constructible_from<quantity_type, Q> &&
(point_origin == default_point_origin(R)) && (implicitly_convertible(Q::quantity_spec, quantity_spec))
constexpr explicit quantity_point(Q&& q) : quantity_from_origin_is_an_implementation_detail_(std::forward<Q>(q))
{
}

// construction from a quantity and matching origin
template<typename Q>
requires QuantityOf<std::remove_cvref_t<Q>, quantity_spec> && std::constructible_from<quantity_type, Q>
constexpr quantity_point(Q&& q, decltype(PO)) : quantity_from_origin_is_an_implementation_detail_(std::forward<Q>(q))
{
}

// construction from a quantity and a related origin
template<typename Q, PointOrigin PO2>
requires Quantity<std::remove_cvref_t<Q>> && std::constructible_from<quantity_type, Q> &&
ReferenceOf<std::remove_const_t<decltype(std::remove_reference_t<Q>::reference)>, PO2::quantity_spec> &&
Expand All @@ -230,19 +233,16 @@ class quantity_point {
{
}

// converting constructor from a quantity_point of related origin
template<QuantityPointOf<absolute_point_origin> QP>
requires std::constructible_from<quantity_type, typename QP::quantity_type>
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(!std::convertible_to<typename QP::quantity_type, quantity_type>) quantity_point(const QP& qp) :
quantity_from_origin_is_an_implementation_detail_([&] {
if constexpr (point_origin == QP::point_origin)
return qp.quantity_ref_from(point_origin);
else
return qp - point_origin;
}())
quantity_point(detail::sudo_cast<quantity_point>(qp))
{
}

// converting constructor from a quantity_point of matching origin
template<QuantityPointLike QP>
requires(quantity_point_like_traits<QP>::point_origin == point_origin) &&
std::convertible_to<
Expand Down

0 comments on commit 3d4d6fc

Please sign in to comment.