+
+// 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> {
+ bool operator() (const ex &lh, const ex &rh) const { return lh.compare(rh) < 0; }
+};
+
+struct ex_is_equal : public std::binary_function<ex, ex, bool> {
+ bool operator() (const ex &lh, const ex &rh) const { return lh.is_equal(rh); }
+};
+
+struct op0_is_equal : public std::binary_function<ex, ex, bool> {
+ bool operator() (const ex &lh, const ex &rh) const { return lh.op(0).is_equal(rh.op(0)); }
+};
+
+struct ex_swap : public std::binary_function<ex, ex, void> {
+ void operator() (ex &lh, ex &rh) const { lh.swap(rh); }
+};
+
+inline ex ex::subs(const exmap & m, unsigned options) const
+{
+ return bp->subs(m, options);
+}
+
+inline ex subs(const ex & thisex, const exmap & m, unsigned options = 0)
+{ return thisex.subs(m, options); }
+
+inline ex subs(const ex & thisex, const lst & ls, const lst & lr, unsigned options = 0)
+{ return thisex.subs(ls, lr, options); }
+
+inline ex subs(const ex & thisex, const ex & e, unsigned options = 0)
+{ return thisex.subs(e, options); }
+
+
+/* Convert function pointer to function object suitable for map(). */
+class pointer_to_map_function : public map_function {
+protected:
+ ex (*ptr)(const ex &);
+public:
+ explicit pointer_to_map_function(ex x(const ex &)) : ptr(x) {}
+ ex operator()(const ex & e) { return ptr(e); }
+};
+
+template<class T1>
+class pointer_to_map_function_1arg : public map_function {
+protected:
+ ex (*ptr)(const ex &, T1);
+ T1 arg1;
+public:
+ explicit pointer_to_map_function_1arg(ex x(const ex &, T1), T1 a1) : ptr(x), arg1(a1) {}
+ ex operator()(const ex & e) { return ptr(e, arg1); }
+};
+
+template<class T1, class T2>
+class pointer_to_map_function_2args : public map_function {
+protected:
+ ex (*ptr)(const ex &, T1, T2);
+ T1 arg1;
+ T2 arg2;
+public:
+ explicit pointer_to_map_function_2args(ex x(const ex &, T1, T2), T1 a1, T2 a2) : ptr(x), arg1(a1), arg2(a2) {}
+ ex operator()(const ex & e) { return ptr(e, arg1, arg2); }
+};
+
+template<class T1, class T2, class T3>
+class pointer_to_map_function_3args : public map_function {
+protected:
+ ex (*ptr)(const ex &, T1, T2, T3);
+ T1 arg1;
+ T2 arg2;
+ T3 arg3;
+public:
+ explicit pointer_to_map_function_3args(ex x(const ex &, T1, T2, T3), T1 a1, T2 a2, T3 a3) : ptr(x), arg1(a1), arg2(a2), arg3(a3) {}
+ ex operator()(const ex & e) { return ptr(e, arg1, arg2, arg3); }
+};
+
+inline ex ex::map(ex f(const ex &)) const
+{
+ pointer_to_map_function fcn(f);
+ return bp->map(fcn);
+}
+
+