// 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
// 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;
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> {
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__