avoid clash of CGAL::min/max with std::min/max

e.g. boost does: "unsing std::min" plus an unqualified call of min
This commit is contained in:
Michael Hemmer 2009-04-29 13:57:45 +00:00
parent 3ce4884475
commit 2561a432dd
12 changed files with 121 additions and 4 deletions

View File

@ -123,11 +123,24 @@ CGAL_BEGIN_NAMESPACE
}
};
// Several libraries do not want to enforce the use of std::min/max
// for the case that there is a special function for min/max
// However, this may be a problem for template CGAL::min/max in case NT is a
// CGAL type. These types have to overload CGAL::min/max.
template<typename NT>
void test_min_max(){
using std:: min BOOST_PREVENT_MACRO_SUBSTITUTION ;
using std:: max BOOST_PREVENT_MACRO_SUBSTITUTION ;
NT x(1),y(2);
assert(min BOOST_PREVENT_MACRO_SUBSTITUTION (x,y)==NT(1));
assert(max BOOST_PREVENT_MACRO_SUBSTITUTION (x,y)==NT(2));
}
//! tests if \c Type is a model for the \c RealComparable concept
//! and terminates the program with an error message if not.
template <class Type>
void test_real_embeddable() {
test_min_max<Type>();
typedef CGAL::Real_embeddable_traits<Type> RET;
CGAL_SNAP_RET_FUNCTORS(RET);
typedef typename RET::Is_real_embeddable Is_real_embeddable;

View File

@ -221,6 +221,18 @@ template <class NT> class Real_embeddable_traits< Nef_polynomial<NT> >
};
};
template <typename NT>
inline Nef_polynomial<NT> min BOOST_PREVENT_MACRO_SUBSTITUTION
(const Nef_polynomial<NT>& x,const Nef_polynomial<NT>& y){
return (x<=y)?x:y;
}
template <typename NT>
inline Nef_polynomial<NT> max BOOST_PREVENT_MACRO_SUBSTITUTION
(const Nef_polynomial<NT>& x,const Nef_polynomial<NT>& y){
return (x>=y)?x:y;
}
template <typename NT>
class Fraction_traits<Nef_polynomial<NT> > {
public:

View File

@ -768,6 +768,19 @@ public:
};
};
template<typename NT> inline
Counted_number<NT> min BOOST_PREVENT_MACRO_SUBSTITUTION(
const Counted_number<NT> & x,
const Counted_number<NT> & y){
return CGAL::Min<Counted_number<NT> > ()(x,y);
}
template<typename NT> inline
Counted_number<NT> max BOOST_PREVENT_MACRO_SUBSTITUTION(
const Counted_number<NT> & x,
const Counted_number<NT> & y){
return CGAL::Max<Counted_number<NT> > ()(x,y);
}
CGAL_END_NAMESPACE
#endif

View File

@ -421,6 +421,14 @@ operator>>(std::istream& is, Gmpq &z)
return is;
}
inline Gmpq min BOOST_PREVENT_MACRO_SUBSTITUTION(const Gmpq& x,const Gmpq& y){
return (x<=y)?x:y;
}
inline Gmpq max BOOST_PREVENT_MACRO_SUBSTITUTION(const Gmpq& x,const Gmpq& y){
return (x>=y)?x:y;
}
CGAL_END_NAMESPACE

View File

@ -454,9 +454,18 @@ struct Split_double<Gmpz>
}
};
inline Gmpz min BOOST_PREVENT_MACRO_SUBSTITUTION(const Gmpz& x,const Gmpz& y){
return (x<=y)?x:y;
}
inline Gmpz max BOOST_PREVENT_MACRO_SUBSTITUTION(const Gmpz& x,const Gmpz& y){
return (x>=y)?x:y;
}
#include <CGAL/auto_link/GMP.h>
#include <CGAL/auto_link/MPFR.h>
CGAL_END_NAMESPACE
#endif // CGAL_GMPZ_TYPE_H

View File

@ -573,6 +573,13 @@ bool operator>(const Gmpzf &a, int b)
return operator>(a, Gmpzf(b));
}
inline Gmpzf min BOOST_PREVENT_MACRO_SUBSTITUTION(const Gmpzf& x,const Gmpzf& y){
return (x<=y)?x:y;
}
inline Gmpzf max BOOST_PREVENT_MACRO_SUBSTITUTION(const Gmpzf& x,const Gmpzf& y){
return (x>=y)?x:y;
}
CGAL_END_NAMESPACE
#endif // CGAL_GMPZF_TYPE_H

View File

@ -788,9 +788,6 @@ operator/ (const Interval_nt<Protected> & a, int b)
}
// TODO: What about these two guys? Where do they belong to?
template <bool Protected>
struct Min <Interval_nt<Protected> >
: public std::binary_function<Interval_nt<Protected>,
@ -821,6 +818,20 @@ struct Max <Interval_nt<Protected> >
}
};
template<bool Protected> inline
Interval_nt<Protected> min BOOST_PREVENT_MACRO_SUBSTITUTION(
const Interval_nt<Protected> & x,
const Interval_nt<Protected> & y){
return CGAL::Min<Interval_nt<Protected> > ()(x,y);
}
template<bool Protected> inline
Interval_nt<Protected> max BOOST_PREVENT_MACRO_SUBSTITUTION(
const Interval_nt<Protected> & x,
const Interval_nt<Protected> & y){
return CGAL::Max<Interval_nt<Protected> > ()(x,y);
}
// TODO : document, when we are OK with the interface.
// - should it allow other number types for the exponent ?

View File

@ -1220,6 +1220,18 @@ struct Max <Lazy_exact_nt<ET> >
}
};
template<typename ET> inline
Lazy_exact_nt<ET> min BOOST_PREVENT_MACRO_SUBSTITUTION(
const Lazy_exact_nt<ET> & x,
const Lazy_exact_nt<ET> & y){
return CGAL::Min<Lazy_exact_nt<ET> > ()(x,y);
}
template<typename ET> inline
Lazy_exact_nt<ET> max BOOST_PREVENT_MACRO_SUBSTITUTION(
const Lazy_exact_nt<ET> & x,
const Lazy_exact_nt<ET> & y){
return CGAL::Max<Lazy_exact_nt<ET> > ()(x,y);
}
template <typename ET>
std::ostream &

View File

@ -822,6 +822,14 @@ public:
};
};
inline MP_Float min BOOST_PREVENT_MACRO_SUBSTITUTION(const MP_Float& x,const MP_Float& y){
return (x<=y)?x:y;
}
inline MP_Float max BOOST_PREVENT_MACRO_SUBSTITUTION(const MP_Float& x,const MP_Float& y){
return (x>=y)?x:y;
}
// TODO:
// // specialization of to double functor
// template<>

View File

@ -1362,6 +1362,17 @@ public:
}
};
template <class NT>
inline const Root_of_2<NT>& min BOOST_PREVENT_MACRO_SUBSTITUTION
(const Root_of_2<NT>& p, const Root_of_2<NT>& q){
return (std::min)(p, q);
}
template <class NT>
inline const Root_of_2<NT>& max BOOST_PREVENT_MACRO_SUBSTITUTION
(const Root_of_2<NT>& p, const Root_of_2<NT>& q){
return (std::max)(p, q);
}
} // namespace CGAL
#undef CGAL_int

View File

@ -88,7 +88,6 @@ class Real_embeddable_traits< Sqrt_extension<COEFF, ROOT> >
}
};
};
CGAL_END_NAMESPACE
#endif

View File

@ -606,6 +606,20 @@ template <class NT,class ROOT> bool operator >
(CGAL_int(NT) num, const Sqrt_extension<NT,ROOT>& p)
{ return ( p.compare(num) == CGAL::SMALLER ); }
template<typename NT, typename ROOT> inline
Sqrt_extension<NT,ROOT> min BOOST_PREVENT_MACRO_SUBSTITUTION(
const Sqrt_extension<NT,ROOT> & x,
const Sqrt_extension<NT,ROOT> & y){
return (std::min)(x,y);
}
template<typename NT, typename ROOT> inline
Sqrt_extension<NT,ROOT> max BOOST_PREVENT_MACRO_SUBSTITUTION(
const Sqrt_extension<NT,ROOT> & x,
const Sqrt_extension<NT,ROOT> & y){
return (std::max)(x,y);
}
CGAL_END_NAMESPACE
#undef CGAL_int