diff --git a/Number_types/include/CGAL/GMP/Gmpq_type.h b/Number_types/include/CGAL/GMP/Gmpq_type.h index 54776eb5b78..156e24c02ba 100644 --- a/Number_types/include/CGAL/GMP/Gmpq_type.h +++ b/Number_types/include/CGAL/GMP/Gmpq_type.h @@ -35,6 +35,10 @@ #include #include +#if __cpp_impl_three_way_comparison >= 201907L +# include +#endif + #if defined(BOOST_MSVC) # pragma warning(push) # pragma warning(disable:4146) @@ -61,8 +65,17 @@ private: class Gmpq - : Handle_for, - boost::totally_ordered1< Gmpq + : Handle_for +#if __cpp_impl_three_way_comparison >= 201907L + , boost::field_operators2< Gmpq, int + , boost::field_operators2< Gmpq, long + , boost::field_operators2< Gmpq, long long + , boost::field_operators2< Gmpq, double + , boost::field_operators2< Gmpq, Gmpz + , boost::field_operators2< Gmpq, Gmpfr + > > > > > > +#else + , boost::totally_ordered1< Gmpq , boost::ordered_field_operators2< Gmpq, int , boost::ordered_field_operators2< Gmpq, long , boost::ordered_field_operators2< Gmpq, long long @@ -70,6 +83,7 @@ class Gmpq , boost::ordered_field_operators2< Gmpq, Gmpz , boost::ordered_field_operators2< Gmpq, Gmpfr > > > > > > > +#endif { typedef Handle_for Base; public: @@ -223,7 +237,11 @@ public: Gmpq& operator/=(const Gmpq &q); bool operator==(const Gmpq &q) const noexcept { return mpq_equal(this->mpq(), q.mpq()) != 0;} +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(const Gmpq&q) const noexcept { return mpq_cmp(this->mpq(), q.mpq()) <=> 0; } +#else bool operator< (const Gmpq &q) const noexcept { return mpq_cmp(this->mpq(), q.mpq()) < 0; } +#endif double to_double() const noexcept; Sign sign() const noexcept; @@ -245,54 +263,78 @@ public: Gmpq& operator-=(int z){return (*this)-= Gmpq(z);} Gmpq& operator*=(int z){return (*this)*= Gmpq(z);} Gmpq& operator/=(int z){return (*this)/= Gmpq(z);} +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(int z) const noexcept { return mpq_cmp_si(mpq(),z,1) <=> 0; } +#else bool operator==(int z) const {return mpq_cmp_si(mpq(),z,1)==0;} bool operator< (int z) const {return mpq_cmp_si(mpq(),z,1)<0;} bool operator> (int z) const {return mpq_cmp_si(mpq(),z,1)>0;} +#endif // Interoperability with long Gmpq& operator+=(long z){return (*this)+= Gmpq(z);} Gmpq& operator-=(long z){return (*this)-= Gmpq(z);} Gmpq& operator*=(long z){return (*this)*= Gmpq(z);} Gmpq& operator/=(long z){return (*this)/= Gmpq(z);} +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(long z) const noexcept { return mpq_cmp_si(mpq(),z,1) <=> 0; } +#else bool operator==(long z) const {return mpq_cmp_si(mpq(),z,1)==0;} bool operator< (long z) const {return mpq_cmp_si(mpq(),z,1)<0;} bool operator> (long z) const {return mpq_cmp_si(mpq(),z,1)>0;} +#endif // Interoperability with long long Gmpq& operator+=(long long z){return (*this)+= Gmpq(z);} Gmpq& operator-=(long long z){return (*this)-= Gmpq(z);} Gmpq& operator*=(long long z){return (*this)*= Gmpq(z);} Gmpq& operator/=(long long z){return (*this)/= Gmpq(z);} +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(long long z) const noexcept { return *this <=> Gmpq(z); } +#else bool operator==(long long z) const {return (*this)== Gmpq(z);} bool operator< (long long z) const {return (*this)< Gmpq(z);} bool operator> (long long z) const {return (*this)> Gmpq(z);} +#endif // Interoperability with double Gmpq& operator+=(double d){return (*this)+= Gmpq(d);} Gmpq& operator-=(double d){return (*this)-= Gmpq(d);} Gmpq& operator*=(double d){return (*this)*= Gmpq(d);} Gmpq& operator/=(double d){return (*this)/= Gmpq(d);} +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(double d) const noexcept { return *this <=> Gmpq(d); } +#else bool operator==(double d) const {return (*this)== Gmpq(d);} bool operator< (double d) const {return (*this)< Gmpq(d);} bool operator> (double d) const {return (*this)> Gmpq(d);} +#endif // Interoperability with Gmpz Gmpq& operator+=(const Gmpz&); Gmpq& operator-=(const Gmpz&); Gmpq& operator*=(const Gmpz&); Gmpq& operator/=(const Gmpz&); +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(const Gmpz& z) const noexcept { return *this <=> Gmpq(z); } +#else bool operator==(const Gmpz &z) const {return (*this)== Gmpq(z);} bool operator< (const Gmpz &z) const {return (*this)< Gmpq(z);} bool operator> (const Gmpz &z) const {return (*this)> Gmpq(z);} +#endif // Interoperability with Gmpfr Gmpq& operator+=(const Gmpfr &f){return (*this)+= Gmpq(f);} Gmpq& operator-=(const Gmpfr &f){return (*this)-= Gmpq(f);} Gmpq& operator*=(const Gmpfr &f){return (*this)*= Gmpq(f);} Gmpq& operator/=(const Gmpfr &f){return (*this)/= Gmpq(f);} +#if __cpp_impl_three_way_comparison >= 201907L + std::strong_ordering operator<=>(const Gmpfr& f) const noexcept { return 0 <=> mpfr_cmp_q(f.fr(),mpq()); } +#else bool operator==(const Gmpfr &f) const {return mpfr_cmp_q(f.fr(),mpq())==0;} bool operator< (const Gmpfr &f) const {return mpfr_cmp_q(f.fr(),mpq())>0;} bool operator> (const Gmpfr &f) const {return mpfr_cmp_q(f.fr(),mpq())<0;} +#endif };