mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 20:34:26 +02:00
feat: CTAD for quantity_point
can now deduce point_origin
This commit is contained in:
@@ -108,7 +108,7 @@ public:
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires std::constructible_from<quantity_type, T>
|
requires std::constructible_from<quantity_type, T>
|
||||||
constexpr explicit quantity_point(T&& v) : q_(std::forward<T>(v))
|
constexpr explicit quantity_point(T&& v, decltype(point_origin) = point_origin) : q_(std::forward<T>(v))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,6 +230,9 @@ public:
|
|||||||
template<Quantity Q>
|
template<Quantity Q>
|
||||||
explicit quantity_point(Q) -> quantity_point<Q::reference, absolute_point_origin<Q::quantity_spec>{}, typename Q::rep>;
|
explicit quantity_point(Q) -> quantity_point<Q::reference, absolute_point_origin<Q::quantity_spec>{}, typename Q::rep>;
|
||||||
|
|
||||||
|
template<Quantity Q, PointOrigin PO>
|
||||||
|
explicit quantity_point(Q, PO) -> quantity_point<Q::reference, PO{}, typename Q::rep>;
|
||||||
|
|
||||||
template<QuantityPointLike QP>
|
template<QuantityPointLike QP>
|
||||||
explicit quantity_point(QP)
|
explicit quantity_point(QP)
|
||||||
-> quantity_point<quantity_point_like_traits<QP>::reference, quantity_point_like_traits<QP>::point_origin,
|
-> quantity_point<quantity_point_like_traits<QP>::reference, quantity_point_like_traits<QP>::point_origin,
|
||||||
|
@@ -39,17 +39,15 @@ using sys_seconds = std::chrono::time_point<std::chrono::system_clock, std::chro
|
|||||||
inline constexpr struct mean_sea_level : absolute_point_origin<isq::height> {
|
inline constexpr struct mean_sea_level : absolute_point_origin<isq::height> {
|
||||||
} mean_sea_level;
|
} mean_sea_level;
|
||||||
|
|
||||||
inline constexpr struct ground_level :
|
inline constexpr struct ground_level : relative_point_origin<quantity_point{42 * isq::height[m], mean_sea_level}> {
|
||||||
relative_point_origin<quantity_point<isq::height[m], mean_sea_level>{42 * isq::height[m]}> {
|
|
||||||
} ground_level;
|
} ground_level;
|
||||||
|
|
||||||
inline constexpr struct tower_peak :
|
inline constexpr struct tower_peak : relative_point_origin<quantity_point{42 * isq::height[m], ground_level}> {
|
||||||
relative_point_origin<quantity_point<isq::height[m], ground_level>{42 * isq::height[m]}> {
|
|
||||||
} tower_peak;
|
} tower_peak;
|
||||||
|
|
||||||
inline constexpr struct everest_base_camp :
|
inline constexpr struct other_ground_level :
|
||||||
relative_point_origin<quantity_point<isq::height[m], mean_sea_level>{5364 * m}> {
|
relative_point_origin<quantity_point{123 * isq::height[m], mean_sea_level}> {
|
||||||
} everest_base_camp;
|
} other_ground_level;
|
||||||
|
|
||||||
QUANTITY_SPEC(special_height, isq::height);
|
QUANTITY_SPEC(special_height, isq::height);
|
||||||
QUANTITY_SPEC(activity, 1 / isq::time);
|
QUANTITY_SPEC(activity, 1 / isq::time);
|
||||||
@@ -492,6 +490,12 @@ static_assert(invalid_unit_conversion<quantity_point>);
|
|||||||
// CTAD
|
// CTAD
|
||||||
/////////
|
/////////
|
||||||
|
|
||||||
|
static_assert(std::is_same_v<std::remove_const_t<decltype(quantity_point{123 * m}.point_origin)>,
|
||||||
|
absolute_point_origin<kind_of<isq::length>>>);
|
||||||
|
static_assert(std::is_same_v<std::remove_const_t<decltype(quantity_point{123 * m, mean_sea_level}.point_origin)>,
|
||||||
|
std::remove_const_t<decltype(mean_sea_level)>>);
|
||||||
|
static_assert(std::is_same_v<std::remove_const_t<decltype(quantity_point{123 * m, ground_level}.point_origin)>,
|
||||||
|
std::remove_const_t<decltype(ground_level)>>);
|
||||||
static_assert(std::is_same_v<decltype(quantity_point{123 * m})::rep, int>);
|
static_assert(std::is_same_v<decltype(quantity_point{123 * m})::rep, int>);
|
||||||
static_assert(std::is_same_v<decltype(quantity_point{123. * m})::rep, double>);
|
static_assert(std::is_same_v<decltype(quantity_point{123. * m})::rep, double>);
|
||||||
static_assert(quantity_point{123. * m}.unit == si::metre);
|
static_assert(quantity_point{123. * m}.unit == si::metre);
|
||||||
|
Reference in New Issue
Block a user