]> www.ginac.de Git - ginac.git/blobdiff - ginac/utils.h
*sigh* when will we move the Makefile.in's out of CVS?
[ginac.git] / ginac / utils.h
index 755881a1f787b180ea6d1169cc67689e3c3b0c2a..7018bc9511a02584ffb885b81bf0cffb9d183a1b 100644 (file)
@@ -34,7 +34,7 @@ namespace GiNaC {
 #endif // ndef NO_NAMESPACE_GINAC
 
 template<class T>
-string ToString(T const & t)
+string ToString(const T & t)
 {
     char buf[256];
     ostrstream(buf,sizeof(buf)) << t << ends;
@@ -138,6 +138,26 @@ OutputIterator mymerge3(InputIterator1 first1, InputIterator1 last1,
     }
 }
 
+// Compute the sign of a permutation of a vector of things.
+template <typename T>
+int permutation_sign(vector<T> s)
+{
+    if (s.size() < 2)
+        return 0;
+    int sigma = 1;
+    for (typename vector<T>::iterator i=s.begin(); i!=s.end()-1; ++i) {
+        for (typename vector<T>::iterator j=i+1; j!=s.end(); ++j) {
+            if (*i == *j)
+                return 0;
+            if (*i > *j) {
+                iter_swap(i,j);
+                sigma = -sigma;
+            }
+        }
+    }
+    return sigma;
+}
+
 // Collection of `construct on first use' wrappers for safely avoiding
 // internal object replication without running into the `static
 // initialization order fiasco'.  This chest of numbers helps speed up