]> www.ginac.de Git - ginac.git/commitdiff
synced with main branch
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 27 Mar 2002 21:27:21 +0000 (21:27 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 27 Mar 2002 21:27:21 +0000 (21:27 +0000)
ginac/ex.cpp
ginac/ex.h
ginac/expair.h

index 8b6a88eaae167a4af1200a64cba14ff2a6f74719..02b73b7af1bc0f677f1d68ea7247f6a02d961b90 100644 (file)
@@ -48,19 +48,6 @@ namespace GiNaC {
 
 // public
        
-/** Efficiently swap the contents of two expressions. */
-void ex::swap(ex & other)
-{
-       GINAC_ASSERT(bp!=0);
-       GINAC_ASSERT(bp->flags & status_flags::dynallocated);
-       GINAC_ASSERT(other.bp!=0);
-       GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
-       
-       basic * tmpbp = bp;
-       bp = other.bp;
-       other.bp = tmpbp;
-}
-
 /** Print expression to stream. The formatting of the output is determined
  *  by the kind of print_context object that is passed. Possible formattings
  *  include ginsh-parsable output (the default), tree-like output for
index ad5980075f720b10f86d41f51698b237ea813c37..cf59b2a1405daadd84c13d19172c489264afe0f5 100644 (file)
@@ -97,7 +97,19 @@ public:
        
        // non-virtual functions in this class
 public:
-       void swap(ex & other);
+       /** Efficiently swap the contents of two expressions. */
+       void swap(ex & other)
+       {
+               GINAC_ASSERT(bp!=0);
+               GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+               GINAC_ASSERT(other.bp!=0);
+               GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
+       
+               basic * tmpbp = bp;
+               bp = other.bp;
+               other.bp = tmpbp;
+       }
+
        void print(const print_context & c, unsigned level = 0) const;
        void printtree(std::ostream & os) const;
        void dbgprint(void) const;
@@ -458,6 +470,10 @@ inline bool is_zero(const ex & thisex)
 inline void swap(ex & e1, ex & e2)
 { e1.swap(e2); }
 
+// This makes STL algorithms use the more efficient swap operation for ex objects
+inline void iter_swap(std::vector<ex>::iterator i1, std::vector<ex>::iterator i2)
+{ i1->swap(*i2); }
+
 
 /* Function objects for STL sort() etc. */
 struct ex_is_less : public std::binary_function<ex, ex, bool> {
index 954442509e40a52cc1f7f370c977368db6e28a79..925db97230ea8f471416b27ccedfe9a1328f6925 100644 (file)
@@ -111,6 +111,13 @@ struct expair_swap : public std::binary_function<expair, expair, void> {
        void operator()(expair &lh, expair &rh) const { lh.swap(rh); }
 };
 
+inline void swap(expair & e1, expair & e2)
+{ e1.swap(e2); }
+
+// This makes STL algorithms use the more efficient swap operation for ex objects
+inline void iter_swap(std::vector<expair>::iterator i1, std::vector<expair>::iterator i2)
+{ i1->swap(*i2); }
+
 } // namespace GiNaC
 
 #endif // ndef __GINAC_EXPAIR_H__