As the C++ Standard Library normally provides overloaded operators for its classes, I was wondering why there are comparison functions(actually not really functions but structs with overloaded ()-operator) but no comparison operators for the std::ratio class(es).
Im my opinion they would provide a lot better use- and readabilty and could be performed on compile-time as well.
Even if their particular solution would need template-metaprogramming using structs, wrapping it into another function like that should be no problem:
template<intmax_t N1, intmax_t D1, intmax_t N2, intmax_t D2>
constexpr bool operator==(const ratio<N1, D1>& first, const ratio<N2, D2>& second) {
return ratio_equal<ratio<N1,D1>, ratio<N2,D2>>();
}
Actually works for me and could be adopted easily for all the other operators as well
So am I missing something or has anyone an idea why they decided not to support operators here?
Most likely back when the proposal N2661 was written, constexpr didn't exist yet. The first occurance of constexpr I found was in N2235, so chances are at least no compiler had it implemented and it was probably not even sure it will be considered in the future standard. That just a guess though, maybe not even worth this answer.
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