Revert "feat: runtime conversion factors between units support added"

This reverts commit cc8a088013.
This commit is contained in:
Mateusz Pusz
2023-05-16 16:41:51 +02:00
parent 81eafbf13e
commit 9322aa25e4
4 changed files with 42 additions and 59 deletions
+13 -14
View File
@@ -39,6 +39,8 @@ inline constexpr struct great_british_pound : named_unit<"GBP", kind_of<currency
inline constexpr struct japanese_jen : named_unit<"JPY", kind_of<currency>> {} japanese_jen;
// clang-format on
static_assert(!std::equality_comparable_with<quantity<euro, int>, quantity<us_dollar, int>>);
#if 0
// if you have only a few currencies to handle
@@ -52,11 +54,6 @@ template<Unit auto From, Unit auto To>
#else
template<AssociatedUnit auto From, AssociatedUnit auto To>
requires(get_quantity_spec(From) == currency && get_quantity_spec(To) == currency)
inline constexpr is_unit_convertible_result mp_units::is_unit_convertible<From, To> =
is_unit_convertible_result::non_integral_factor;
[[nodiscard]] std::string_view to_string_view(Unit auto u) { return u.symbol.ascii().c_str(); }
template<Unit auto From, Unit auto To>
@@ -72,21 +69,23 @@ template<Unit auto From, Unit auto To>
#endif
template<typename Rep, AssociatedUnit From, AssociatedUnit To>
[[nodiscard]] Rep scale_quantity_number(Rep v, From from, To to)
requires(get_quantity_spec(from) == currency && get_quantity_spec(to) == currency)
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<from, to>() * v);
return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.number()) * To;
}
static_assert(!std::equality_comparable_with<quantity<euro>, quantity<us_dollar>>);
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)
{
return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.absolute().number()) * To;
}
int main()
{
auto price_usd = quantity_point{100. * us_dollar};
auto price_euro = quantity_point{price_usd[euro]};
auto price_usd = quantity_point{100 * us_dollar};
auto price_euro = quantity_point{exchange_to<euro>(price_usd)};
std::cout << price_usd.absolute() << " -> " << price_euro.absolute() << "\n";
// std::cout << price_usd.absolute() + price_euro.absolute() << "\n"; // does not compile
// std::cout << price_euro.absolute() + price_usd.absolute() << "\n"; // does not compile
}
}