]> www.ginac.de Git - ginac.git/commitdiff
Fix compilation failure due to (template) operator- defined in factor.cpp
authorAlexei Sheplyakov <varg@metalica.kh.ua>
Mon, 23 Feb 2009 12:03:16 +0000 (14:03 +0200)
committerJens Vollinga <jensv@nikhef.nl>
Wed, 25 Feb 2009 11:43:15 +0000 (12:43 +0100)
GiNaC 1.5.0 fails to compile with g++ 3.4.
The fix is simple: declare (and define) operator- (and operator+) only
for (univariate) polynomials.

ginac/factor.cpp

index b8a1fb8ed296dc0b2a5a573e9c390d984c6b1512..2f9157b97a81082c0b38ab11873b820af6dcdaa3 100644 (file)
@@ -218,8 +218,32 @@ static void expt_pos(umodpoly& a, unsigned int q)
        }
 }
 
        }
 }
 
+template<bool COND, typename T = void> struct enable_if
+{
+       typedef T type;
+};
+
+template<typename T> struct enable_if<false, T> { /* empty */ };
+
+template<typename T> struct uvar_poly_p
+{
+       static const bool value = false;
+};
+
+template<> struct uvar_poly_p<upoly>
+{
+       static const bool value = true;
+};
+
+template<> struct uvar_poly_p<umodpoly>
+{
+       static const bool value = true;
+};
+
 template<typename T>
 template<typename T>
-static T operator+(const T& a, const T& b)
+// Don't define this for anything but univariate polynomials.
+static typename enable_if<uvar_poly_p<T>::value, T>::type
+operator+(const T& a, const T& b)
 {
        int sa = a.size();
        int sb = b.size();
 {
        int sa = a.size();
        int sb = b.size();
@@ -250,7 +274,11 @@ static T operator+(const T& a, const T& b)
 }
 
 template<typename T>
 }
 
 template<typename T>
-static T operator-(const T& a, const T& b)
+// Don't define this for anything but univariate polynomials. Otherwise
+// overload resolution might fail (this actually happens when compiling
+// GiNaC with g++ 3.4).
+static typename enable_if<uvar_poly_p<T>::value, T>::type
+operator-(const T& a, const T& b)
 {
        int sa = a.size();
        int sb = b.size();
 {
        int sa = a.size();
        int sb = b.size();