diff --git a/example/currency.cpp b/example/currency.cpp index c3a46b01..17ae7384 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -68,17 +69,23 @@ double exchange_rate() #endif -template auto To> -quantity exchange_to(QuantityOf auto q) +template auto To, ReferenceOf auto From, typename Rep> +quantity exchange_to(quantity q) { - return static_cast(exchange_rate() * q.number()) * euro; + return static_cast(exchange_rate() * q.number()) * To; +} + +template auto To, ReferenceOf auto From, auto PO, typename Rep> +quantity_point exchange_to(quantity_point q) +{ + return static_cast(exchange_rate() * q.absolute().number()) * To; } int main() { - auto price_usd = 100 * us_dollar; - auto price_euro = exchange_to(price_usd); + auto price_usd = quantity_point{100 * us_dollar}; + auto price_euro = quantity_point{exchange_to(price_usd)}; - std::cout << price_usd << " -> " << price_euro << "\n"; - // std::cout << price_usd + price_euro << "\n"; // does not compile -} + std::cout << price_usd.absolute() << " -> " << price_euro.absolute() << "\n"; + // std::cout << price_usd.absolute() + price_euro.absolute() << "\n"; // does not compile +} \ No newline at end of file