From c94cbc55628a5ccf536dfc63c5512d626ae647b6 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Wed, 20 Aug 2003 20:56:59 +0000 Subject: [PATCH 1/1] cleaned up specializations of swap()/iter_swap() --- ginac/ex.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/ginac/ex.h b/ginac/ex.h index 30a009eb..1f4ead98 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -604,12 +604,6 @@ 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::iterator i1, std::vector::iterator i2) -{ i1->swap(*i2); } - - /* Function objects for STL sort() etc. */ struct ex_is_less : public std::binary_function { bool operator() (const ex &lh, const ex &rh) const { return lh.compare(rh) < 0; } @@ -723,4 +717,31 @@ inline const T &ex_to(const ex &e) } // namespace GiNaC + +// Specializations of Standard Library algorithms +namespace std { + +/** Specialization of std::swap() for ex objects. */ +template <> +inline void swap(GiNaC::ex &a, GiNaC::ex &b) +{ + a.swap(b); +} + +/** Specialization of std::iter_swap() for vector iterators. */ +template <> +inline void iter_swap(vector::iterator i1, vector::iterator i2) +{ + i1->swap(*i2); +} + +/** Specialization of std::iter_swap() for list iterators. */ +template <> +inline void iter_swap(list::iterator i1, list::iterator i2) +{ + i1->swap(*i2); +} + +} // namespace std + #endif // ndef __GINAC_EX_H__ -- 2.44.0