[msvc][fix] CTAD for quantity_point does not work.

This commit is contained in:
Jonas Hoppe
2024-08-30 13:18:27 +02:00
parent d491758697
commit e9ad43a71a
2 changed files with 23 additions and 24 deletions

View File

@ -90,11 +90,11 @@ template<Unit auto From, Unit auto To>
#endif
template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, typename Rep>
quantity<To, Rep> exchange_to(quantity<From, Rep> q)
{
return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.numerical_value()) * To;
}
// template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, typename Rep>
// quantity<To, Rep> exchange_to(quantity<From, Rep> q)
// {
// return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.numerical_value()) * To;
// }
template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, auto PO, typename Rep>
quantity_point<To, PO, Rep> exchange_to(quantity_point<From, PO, Rep> q)
@ -107,8 +107,8 @@ int main()
{
using namespace unit_symbols;
const quantity_point price_usd{100 * USD};
const quantity_point price_euro = exchange_to<euro>(price_usd);
const mp_units::quantity_point price_usd{100 * USD};
const mp_units::quantity_point<euro, default_point_origin(euro), int> price_euro = exchange_to<euro>(price_usd);
std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n";
// std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does

View File

@ -926,13 +926,12 @@ static_assert(quantity_point{sys_seconds{24h}}.quantity_spec == kind_of<isq::tim
////////////
// getters
////////////
constexpr quantity_point mean_sea_level_qp = mean_sea_level + 1 * m;
constexpr quantity_point my_mean_sea_level_qp = my_mean_sea_level + 1 * m;
constexpr quantity_point ground_level_qp = ground_level + 1 * m;
constexpr quantity_point my_ground_level_qp = my_ground_level + 1 * m;
constexpr quantity_point same_ground_level1_qp = same_ground_level1 + 1 * m;
constexpr quantity_point same_ground_level2_qp = same_ground_level2 + 1 * m;
constexpr QuantityPoint auto mean_sea_level_qp = mean_sea_level + (1 * m);
constexpr QuantityPoint auto my_mean_sea_level_qp = my_mean_sea_level + 1 * m;
constexpr QuantityPoint auto ground_level_qp = ground_level + 1 * m;
constexpr QuantityPoint auto my_ground_level_qp = my_ground_level + 1 * m;
constexpr QuantityPoint auto same_ground_level1_qp = same_ground_level1 + 1 * m;
constexpr QuantityPoint auto same_ground_level2_qp = same_ground_level2 + 1 * m;
static_assert(mean_sea_level_qp.quantity_ref_from(mean_sea_level) == 1 * m);
static_assert(mean_sea_level_qp.quantity_ref_from(my_mean_sea_level) == 1 * m);
@ -957,24 +956,24 @@ static_assert(same_ground_level2_qp.quantity_ref_from(same_ground_level1) == 1 *
static_assert(same_ground_level2_qp.quantity_ref_from(same_ground_level2) == 1 * m);
////////////////////////
// assignment operator
////////////////////////
// ////////////////////////
// //assignment operator
// ////////////////////////
static_assert(([]() {
const quantity_point l1{mean_sea_level + 1 * m};
quantity_point l2{mean_sea_level + 2 * m};
const QuantityPoint auto l1{mean_sea_level + 1 * m};
QuantityPoint auto l2{mean_sea_level + 2 * m};
return l2 = l1;
}())
.quantity_from(mean_sea_level) == 1 * m);
static_assert(([]() {
const quantity_point l1{mean_sea_level + 1 * m};
quantity_point l2{mean_sea_level + 2 * m};
const QuantityPoint auto l1{mean_sea_level + 1 * m};
QuantityPoint auto l2{mean_sea_level + 2 * m};
return l2 = l1;
}())
.quantity_from(mean_sea_level) == 1 * m);
static_assert(([]() {
quantity_point l1{mean_sea_level + 1 * m}, l2{mean_sea_level + 2 * m};
QuantityPoint auto l1{mean_sea_level + 1 * m}, l2{mean_sea_level + 2 * m};
return l2 = std::move(l1); // NOLINT(*-move-const-arg)
}())
.quantity_from(mean_sea_level) == 1 * m);
@ -987,7 +986,7 @@ static_assert(([]() {
static_assert([](auto v) {
auto vv = v++; // NOLINT(bugprone-inc-dec-in-conditions)
return std::pair(v, vv);
}(mean_sea_level + 123 * m) == std::pair(mean_sea_level + 124 * m, quantity_point(mean_sea_level + 123 * m)));
}(mean_sea_level + 123 * m) == std::pair(mean_sea_level + 124 * m, mean_sea_level + 123 * m));
static_assert([](auto v) {
auto vv = ++v; // NOLINT(bugprone-inc-dec-in-conditions)
return std::pair(v, vv);
@ -1643,7 +1642,7 @@ static_assert(is_of_type<(zero_Hz + 5 * isq::frequency[Hz]) - (zero_Hz + 10 / (2
static_assert((quantity_point{10 / (2 * isq::period_duration[s])} + 5 * isq::frequency[Hz]).quantity_from_zero() ==
10 * isq::frequency[Hz]);
static_assert((10 / (2 * isq::period_duration[s]) + quantity_point{zero_Hz + 5 * isq::frequency[Hz]})
static_assert((10 / (2 * isq::period_duration[s]) + (zero_Hz + 5 * isq::frequency[Hz]))
.quantity_from_zero() == 10 * isq::frequency[Hz]);
static_assert((quantity_point{5 * isq::frequency[Hz]} + 10 / (2 * isq::period_duration[s])).quantity_from_zero() ==
10 * isq::frequency[Hz]);