forked from mpusz/mp-units
Merge branch 'downcasting_2.0'
This commit is contained in:
@@ -35,6 +35,9 @@ namespace {
|
||||
using namespace units;
|
||||
using namespace units::physical::si;
|
||||
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
||||
|
||||
// class invariants
|
||||
|
||||
template<typename DimLength>
|
||||
@@ -119,23 +122,23 @@ static_assert((quantity_point(2_q_m) -= 1_q_m).relative().count() == 1);
|
||||
|
||||
// non-member arithmetic operators
|
||||
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, metre, int>() + length<metre, double>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, metre, int>() + length<metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
static_assert(compare<decltype(length<metre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, kilometre, int>() + length<metre, double>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, kilometre, int>() + length<metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<kilometre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
static_assert(compare<decltype(length<kilometre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, metre, double>() - length<metre, int>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, metre, double>() - length<metre, int>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, kilometre, double>() - length<metre, int>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, kilometre, double>() - length<metre, int>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(quantity_point<dim_length, metre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
compare<decltype(quantity_point<dim_length, metre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
length<metre, double>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(quantity_point<dim_length, kilometre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
compare<decltype(quantity_point<dim_length, kilometre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
length<metre, double>>);
|
||||
|
||||
static_assert((1_q_m + km).relative().count() == 1001);
|
||||
@@ -187,13 +190,13 @@ static_assert(QuantityPoint<quantity_point<dim_length, millimetre, int>>);
|
||||
|
||||
// common_quantity_point
|
||||
|
||||
static_assert(is_same_v<
|
||||
static_assert(compare<
|
||||
common_quantity_point<quantity_point<dim_length, metre, int>, quantity_point<dim_length, kilometre, int>>,
|
||||
quantity_point<dim_length, metre, int>>);
|
||||
static_assert(is_same_v<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
static_assert(compare<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
quantity_point<dim_length, metre, int>>,
|
||||
quantity_point<dim_length, metre, long long>>);
|
||||
static_assert(is_same_v<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
static_assert(compare<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
quantity_point<dim_length, millimetre, double>>,
|
||||
quantity_point<dim_length, millimetre, double>>);
|
||||
|
||||
@@ -208,8 +211,7 @@ static_assert(std::equality_comparable_with<decltype(quantity_point(1_q_m)), dec
|
||||
|
||||
// quantity_cast
|
||||
|
||||
static_assert(
|
||||
is_same_v<decltype(quantity_point_cast<scaled_unit<ratio(1), metre>>(quantity_point(2_q_km)))::unit, metre>);
|
||||
static_assert(compare<decltype(quantity_point_cast<scaled_unit<ratio(1), metre>>(quantity_point(2_q_km)))::unit, metre>);
|
||||
|
||||
static_assert(quantity_point_cast<quantity_point<dim_length, metre, int>>(quantity_point(2_q_km)).relative().count() ==
|
||||
2000);
|
||||
|
||||
Reference in New Issue
Block a user