Skip to content

Commit

Permalink
Merge pull request #3817 from brdvd/feat/three-way-comparison
Browse files Browse the repository at this point in the history
Use spaceship operator for fractions
  • Loading branch information
lpugin authored Oct 7, 2024
2 parents 8a846f2 + 151e6d0 commit 5ffd814
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
12 changes: 3 additions & 9 deletions include/vrv/horizontalaligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,8 @@ class Fraction {

/** Equality operator */
bool operator==(const Fraction &other) const;
/** Less than operator */
bool operator<(const Fraction &other) const;
/** Less than or equal operator */
bool operator<=(const Fraction &other) const;
/** Greater than operator */
bool operator>(const Fraction &other) const;
/** Greater than or equal operator */
bool operator>=(const Fraction &other) const;
/** Ordering operator */
std::strong_ordering operator<=>(const Fraction &other) const;

/** Getters */
int GetNumerator() const { return m_numerator; }
Expand All @@ -114,7 +108,7 @@ class Fraction {
// Static methods //
//----------------//

/** Reduce the faction represented by the two numbers */
/** Reduce the fraction represented by the two numbers */
static void Reduce(int &numerator, int &denominator);

private:
Expand Down
19 changes: 2 additions & 17 deletions src/horizontalaligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,9 @@ bool Fraction::operator==(const Fraction &other) const
return m_numerator * other.m_denominator == other.m_numerator * m_denominator;
}

bool Fraction::operator<(const Fraction &other) const
std::strong_ordering Fraction::operator<=>(const Fraction &other) const
{
return m_numerator * other.m_denominator < other.m_numerator * m_denominator;
}

bool Fraction::operator<=(const Fraction &other) const
{
return m_numerator * other.m_denominator <= other.m_numerator * m_denominator;
}

bool Fraction::operator>(const Fraction &other) const
{
return m_numerator * other.m_denominator > other.m_numerator * m_denominator;
}

bool Fraction::operator>=(const Fraction &other) const
{
return m_numerator * other.m_denominator >= other.m_numerator * m_denominator;
return m_numerator * other.m_denominator <=> other.m_numerator * m_denominator;
}

double Fraction::ToDouble() const
Expand Down

0 comments on commit 5ffd814

Please sign in to comment.