I was looking at the class std::ratio<>
from the C++11 standard that allows to make compile-time rational arithmetic.
I found the template design and the operations implemented with classes overly complex and did not find any reason why they could not just use a more straightforward and intuitive approach by implementing a really simple rational class and defining constexpr
functions for the operators. The result would have been a class easier to use and the compile-time advantages would have remained.
Does anyone have any idea of the advantages of the current std::ratio<>
design compared to a simple class implementation using constexpr
? Actually, I can't manage to find any advantage to the current implementation.
When N2661 was proposed, none of the proposal authors had access to a compiler which implemented constexpr
. And none of us were willing to propose something we could not build and test. So whether or not a better design could have been done with constexpr
was not even part of the consideration for the design. The design was based on only those tools available to the authors at the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With