mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +02:00
feat: quantity
and quantity_point
conversion operators now can also convert to const references
This commit is contained in:
@@ -143,7 +143,7 @@ public:
|
|||||||
quantity& operator=(const quantity&) = default;
|
quantity& operator=(const quantity&) = default;
|
||||||
quantity& operator=(quantity&&) = default;
|
quantity& operator=(quantity&&) = default;
|
||||||
|
|
||||||
// conversions
|
// unit conversions
|
||||||
template<UnitCompatibleWith<unit, quantity_spec> U>
|
template<UnitCompatibleWith<unit, quantity_spec> U>
|
||||||
requires detail::QuantityConvertibleTo<quantity, quantity<detail::make_reference(quantity_spec, U{}), Rep>>
|
requires detail::QuantityConvertibleTo<quantity, quantity<detail::make_reference(quantity_spec, U{}), Rep>>
|
||||||
[[nodiscard]] constexpr Quantity auto in(U) const
|
[[nodiscard]] constexpr Quantity auto in(U) const
|
||||||
@@ -192,7 +192,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// conversion operators
|
// conversion operators
|
||||||
template<QuantityLike Q>
|
template<typename Q>
|
||||||
|
requires QuantityLike<std::remove_cvref_t<Q>>
|
||||||
[[nodiscard]] explicit(is_specialization_of<decltype(quantity_like_traits<Q>::from_numerical_value(numerical_value_)),
|
[[nodiscard]] explicit(is_specialization_of<decltype(quantity_like_traits<Q>::from_numerical_value(numerical_value_)),
|
||||||
convert_explicitly>) constexpr
|
convert_explicitly>) constexpr
|
||||||
operator Q() const& noexcept(noexcept(quantity_like_traits<Q>::from_numerical_value(numerical_value_)) &&
|
operator Q() const& noexcept(noexcept(quantity_like_traits<Q>::from_numerical_value(numerical_value_)) &&
|
||||||
@@ -201,11 +202,12 @@ public:
|
|||||||
return quantity_like_traits<Q>::from_numerical_value(numerical_value_).value;
|
return quantity_like_traits<Q>::from_numerical_value(numerical_value_).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<QuantityLike Q>
|
template<typename Q>
|
||||||
|
requires QuantityLike<std::remove_cvref_t<Q>>
|
||||||
[[nodiscard]] explicit(is_specialization_of<decltype(quantity_like_traits<Q>::from_numerical_value(numerical_value_)),
|
[[nodiscard]] explicit(is_specialization_of<decltype(quantity_like_traits<Q>::from_numerical_value(numerical_value_)),
|
||||||
convert_explicitly>) constexpr
|
convert_explicitly>) constexpr
|
||||||
operator Q() && noexcept(noexcept(quantity_like_traits<Q>::from_numerical_value(numerical_value_)) &&
|
operator Q() && noexcept(noexcept(quantity_like_traits<Q>::from_numerical_value(numerical_value_)) &&
|
||||||
std::is_nothrow_move_constructible_v<rep>)
|
std::is_nothrow_move_constructible_v<rep>)
|
||||||
{
|
{
|
||||||
return quantity_like_traits<Q>::from_numerical_value(std::move(numerical_value_)).value;
|
return quantity_like_traits<Q>::from_numerical_value(std::move(numerical_value_)).value;
|
||||||
}
|
}
|
||||||
|
@@ -170,6 +170,7 @@ public:
|
|||||||
return *this - PO2{};
|
return *this - PO2{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unit conversions
|
||||||
template<UnitCompatibleWith<unit, quantity_spec> U>
|
template<UnitCompatibleWith<unit, quantity_spec> U>
|
||||||
requires detail::QuantityConvertibleTo<quantity_type, quantity<detail::make_reference(quantity_spec, U{}), Rep>>
|
requires detail::QuantityConvertibleTo<quantity_type, quantity<detail::make_reference(quantity_spec, U{}), Rep>>
|
||||||
[[nodiscard]] constexpr QuantityPoint auto in(U) const
|
[[nodiscard]] constexpr QuantityPoint auto in(U) const
|
||||||
@@ -185,7 +186,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// conversion operators
|
// conversion operators
|
||||||
template<QuantityPointLike QP>
|
template<typename QP>
|
||||||
|
requires QuantityPointLike<std::remove_cvref_t<QP>>
|
||||||
[[nodiscard]] explicit(
|
[[nodiscard]] explicit(
|
||||||
is_specialization_of<decltype(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_)),
|
is_specialization_of<decltype(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_)),
|
||||||
convert_explicitly>) constexpr
|
convert_explicitly>) constexpr
|
||||||
@@ -195,12 +197,13 @@ public:
|
|||||||
return quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_).value;
|
return quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<QuantityPointLike QP>
|
template<typename QP>
|
||||||
|
requires QuantityPointLike<std::remove_cvref_t<QP>>
|
||||||
[[nodiscard]] explicit(
|
[[nodiscard]] explicit(
|
||||||
is_specialization_of<decltype(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_)),
|
is_specialization_of<decltype(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_)),
|
||||||
convert_explicitly>) constexpr
|
convert_explicitly>) constexpr
|
||||||
operator QP() && noexcept(noexcept(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_)) &&
|
operator QP() && noexcept(noexcept(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_)) &&
|
||||||
std::is_nothrow_move_constructible_v<rep>)
|
std::is_nothrow_move_constructible_v<rep>)
|
||||||
{
|
{
|
||||||
return quantity_point_like_traits<QP>::from_quantity(std::move(quantity_from_origin_)).value;
|
return quantity_point_like_traits<QP>::from_quantity(std::move(quantity_from_origin_)).value;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user