i don't see why, if you're already doing all the logic in the helper function, you don't go all the way and do all the logic
bool do_op(const Rational& lhs, const Rational& rhs, std::function<bool(const int, const int)> OP) {
if(lhs.denominator == rhs.denominator)
return OP(lhs.numerator, rhs.numerator);
const int n_l = lhs.numerator * rhs.denominator;
const int n_r = rhs.numerator * lhs.denominator;
return OP(n_l, n_r);
}
bool Rational::operator<(const Rational& other) const {
return do_op(*this, other, std::less<int>{});
}
bool Rational::operator<=(const Rational& other) const {
return !do_op(*this, other, std::greater<int>{});
}
bool Rational::operator>(const Rational& other) const {
return do_op(*this, other, std::greater<int>{});
}
bool Rational::operator>=(const Rational& other) const {
return !do_op(*this, other, std::less<int>{});
}
bool Rational::operator==(const Rational& other) const {
return do_op(*this, other, std::equal_to<int>{});
}
bool Rational::operator!=(const Rational& other) const {
return !do_op(*this, other, std::equal_to<int>{});
}