Date: Thu, 14 Mar 2024 17:48:02 +0000
> The `Money` class seems isomorphic to Mateusz Pusz (cc'ed)'s work with mp_units. You should look into the state of WG21 proposals around "units library."
It would be interesting to hear from Mateusz (or, I bet, he's written something somewhere already) on the question of whether there are important/insurmountable differences between physical units like "meter" and monetary units like "euro," or whether the same C++ approach can work for both just fine. I can't think of any differences — except that monetary units should never be interconverted without some kind of GetCurrentExchangeRate sigilling — but I also wouldn't be terribly surprised to hear that there were some subtle-but-insurmountable differences in practice.
I can answer that question. Money conversions are not a compile time constant, which is a requirement for mp-units, even if you were to get the exchange rate from a market (ex.1$ = 0.92€) the value is not accurate, if you have $5M nobody is going to give you 4.6M€, money doesn’t work like that. You are going to have to sell it to someone else who wants to buy and the actual rate is going to be whatever you will manage to get in the future. And also converting the other way around might be a different rate, or converting it trough a third coin, and you may need to account transaction fees, etc...
And if you are dealing with applications like accounting, there are different per country per application rules in terms of “what rates” are allowed to be used for tax purposes.
For it to be practical the types must be unconvertible to each other, and would require a “exchange facility” to do the conversion depending on what is acceptable, and that is always going to be application specific.
Received on 2024-03-14 17:48:06