mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +02:00
refactor(example): [[nodiscard]]
added for currency
This commit is contained in:
@@ -45,7 +45,7 @@ static_assert(!std::equality_comparable_with<quantity<euro, int>, quantity<us_do
|
|||||||
|
|
||||||
// if you have only a few currencies to handle
|
// if you have only a few currencies to handle
|
||||||
template<Unit auto From, Unit auto To>
|
template<Unit auto From, Unit auto To>
|
||||||
double exchange_rate()
|
[[nodiscard]] double exchange_rate()
|
||||||
{
|
{
|
||||||
if constexpr (From == us_dollar && To == euro) return 0.9215;
|
if constexpr (From == us_dollar && To == euro) return 0.9215;
|
||||||
else if constexpr (From == euro && To == us_dollar) return 1.0848;
|
else if constexpr (From == euro && To == us_dollar) return 1.0848;
|
||||||
@@ -54,10 +54,10 @@ double exchange_rate()
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
std::string_view to_string_view(Unit auto u) { return u.symbol.ascii().c_str(); }
|
[[nodiscard]] std::string_view to_string_view(Unit auto u) { return u.symbol.ascii().c_str(); }
|
||||||
|
|
||||||
template<Unit auto From, Unit auto To>
|
template<Unit auto From, Unit auto To>
|
||||||
double exchange_rate()
|
[[nodiscard]] double exchange_rate()
|
||||||
{
|
{
|
||||||
static std::map<std::pair<std::string_view, std::string_view>, double> rates = {
|
static std::map<std::pair<std::string_view, std::string_view>, double> rates = {
|
||||||
{{"USD", "EUR"}, 0.9215}, {{"EUR", "USD"}, 1.0848},
|
{{"USD", "EUR"}, 0.9215}, {{"EUR", "USD"}, 1.0848},
|
||||||
|
Reference in New Issue
Block a user