]> www.ginac.de Git - ginac.git/blob - ginac/ex.h
removed unused function
[ginac.git] / ginac / ex.h
1 /** @file ex.h
2  *
3  *  Interface to GiNaC's light-weight expression handles. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef __GINAC_EX_H__
24 #define __GINAC_EX_H__
25
26 #include <iosfwd>
27 #include <iterator>
28 #include <functional>
29
30 #include "basic.h"
31 #include "ptr.h"
32
33 namespace GiNaC {
34
35
36 /** Helper class to initialize the library.  There must be one static object
37  *  of this class in every object file that makes use of our flyweights in
38  *  order to guarantee proper initialization.  Hence we put it into this
39  *  file which is included by every relevant file anyways.  This is modeled
40  *  after section 27.4.2.1.6 of the C++ standard, where cout and friends are
41  *  set up.
42  *
43  *  @see utils.cpp */
44 class library_init {
45 public:
46         library_init();
47         ~library_init();
48 private:
49         static int count;
50 };
51 /** For construction of flyweights, etc. */
52 static library_init library_initializer;
53
54
55 class scalar_products;
56
57
58 /** Lightweight wrapper for GiNaC's symbolic objects.  Basically all it does is
59  *  to hold a pointer to the other objects, manage the reference counting and
60  *  provide methods for manipulation of these objects.  (Some people call such
61  *  a thing a proxy class.) */
62 class ex
63 {
64         friend class archive_node;
65         friend inline bool are_ex_trivially_equal(const ex &, const ex &);
66         template<class T> friend inline const T &ex_to(const ex &);
67         template<class T> friend inline bool is_a(const ex &);
68         template<class T> friend inline bool is_exactly_a(const ex &);
69         
70         // default constructor, copy constructor and assignment operator
71 public:
72         ex();
73 #ifdef OBSCURE_CINT_HACK
74         ex(const ex & other);
75         ex & operator=(const ex & other);
76 #endif
77
78         // other constructors
79 public:
80         ex(const basic & other);
81         ex(int i);
82         ex(unsigned int i);
83         ex(long i);
84         ex(unsigned long i);
85         ex(double const d);
86
87         /** Construct ex from string and a list of symbols. The input grammar is
88          *  similar to the GiNaC output format. All symbols and indices to be used
89          *  in the expression must be specified in a lst in the second argument.
90          *  Undefined symbols and other parser errors will throw an exception. */
91         ex(const std::string &s, const ex &l);
92         
93 public:
94         // Iterators
95         class const_iterator : public std::iterator<std::random_access_iterator_tag, ex, ptrdiff_t, const ex *, const ex &>
96         {
97                 friend class ex;
98
99         public:
100                 const_iterator() {}
101                 const_iterator(const basic *bp_, size_t i_) : bp(bp_), i(i_) {}
102
103                 bool operator==(const const_iterator &other) const
104                 {
105                         return bp == other.bp && i == other.i;
106                 }
107
108                 bool operator!=(const const_iterator &other) const
109                 {
110                         return !(*this == other);
111                 }
112
113                 bool operator<(const const_iterator &other) const
114                 {
115                         return i < other.i;
116                 }
117
118                 bool operator>(const const_iterator &other) const
119                 {
120                         return other < *this;
121                 }
122
123                 bool operator<=(const const_iterator &other) const
124                 {
125                         return !(other < *this);
126                 }
127
128                 bool operator>=(const const_iterator &other) const
129                 {
130                         return !(*this < other);
131                 }
132
133                 // This should return an ex&, but that would be a reference to a
134                 // temporary value
135                 ex operator*() const
136                 {
137                         return bp->op(i);
138                 }
139
140 #if 0
141                 // How do we make this work in the context of the "reference to
142                 // temporary" problem? Return an auto_ptr?
143                 pointer operator->() const
144                 {
145                         return &(operator*());
146                 }
147 #endif
148
149                 const_iterator &operator++()
150                 {
151                         ++i;
152                         return *this;
153                 }
154
155                 const_iterator operator++(int)
156                 {
157                         const_iterator tmp = *this;
158                         ++i;
159                         return tmp;
160                 }
161
162                 const_iterator &operator+=(difference_type n)
163                 {
164                         i += n;
165                         return *this;
166                 }
167
168                 const_iterator operator+(difference_type n) const
169                 {
170                         return const_iterator(bp, i + n);
171                 }
172
173                 inline friend const_iterator operator+(difference_type n, const const_iterator &it)
174                 {
175                         return const_iterator(it.bp, it.i + n);
176                 }
177
178                 const_iterator &operator--()
179                 {
180                         --i;
181                         return *this;
182                 }
183
184                 const_iterator operator--(int)
185                 {
186                         const_iterator tmp = *this;
187                         --i;
188                         return tmp;
189                 }
190
191                 const_iterator &operator-=(difference_type n)
192                 {
193                         i -= n;
194                         return *this;
195                 }
196
197                 const_iterator operator-(difference_type n) const
198                 {
199                         return const_iterator(bp, i - n);
200                 }
201
202                 inline friend difference_type operator-(const const_iterator &lhs, const const_iterator &rhs)
203                 {
204                         return lhs.i - rhs.i;
205                 }
206
207                 reference operator[](difference_type n) const
208                 {
209                 }
210
211         protected:
212                 const basic *bp;
213                 size_t i;
214         };
215
216         const_iterator begin() const { return const_iterator(get_pointer(bp), 0); }
217         const_iterator end() const { return const_iterator(get_pointer(bp), bp->nops()); }
218
219 #if 0
220         // This doesn't work because of the "reference to temporary" problem
221         // in operator*()
222         typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
223         const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
224         const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
225 #endif
226
227         // non-virtual functions in this class
228 public:
229         /** Efficiently swap the contents of two expressions. */
230         void swap(ex & other)
231         {
232                 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
233                 GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
234                 bp.swap(other.bp);
235         }
236
237         // evaluation
238         ex eval(int level = 0) const { return bp->eval(level); }
239         ex evalf(int level = 0) const { return bp->evalf(level); }
240         ex evalm() const { return bp->evalm(); }
241         ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); }
242
243         // printing
244         void print(const print_context & c, unsigned level = 0) const;
245         void dbgprint() const;
246         void dbgprinttree() const;
247
248         // info
249         bool info(unsigned inf) const { return bp->info(inf); }
250
251         // operand access
252         size_t nops() const { return bp->nops(); }
253         ex op(size_t i) const { return bp->op(i); }
254         ex operator[](const ex & index) const { return (*bp)[index]; }
255         ex operator[](size_t i) const { return (*bp)[i]; }
256         ex & let_op(size_t i);
257         ex & operator[](const ex & index);
258         ex & operator[](size_t i);
259         ex lhs() const;
260         ex rhs() const;
261
262         // pattern matching
263         bool has(const ex & pattern) const { return bp->has(pattern); }
264         bool find(const ex & pattern, lst & found) const;
265         bool match(const ex & pattern) const;
266         bool match(const ex & pattern, lst & repl_lst) const { return bp->match(pattern, repl_lst); }
267
268         // substitutions
269         ex subs(const exmap & m, unsigned options = 0) const;
270         ex subs(const lst & ls, const lst & lr, unsigned options = 0) const;
271         ex subs(const ex & e, unsigned options = 0) const;
272
273         // function mapping
274         ex map(map_function & f) const { return bp->map(f); }
275         ex map(ex (*f)(const ex & e)) const;
276
277         // visitors and tree traversal
278         void accept(visitor & v) const { bp->accept(v); }
279         void traverse_preorder(visitor & v) const;
280         void traverse_postorder(visitor & v) const;
281         void traverse(visitor & v) const { traverse_preorder(v); }
282
283         // degree/coeff
284         int degree(const ex & s) const { return bp->degree(s); }
285         int ldegree(const ex & s) const { return bp->ldegree(s); }
286         ex coeff(const ex & s, int n = 1) const { return bp->coeff(s, n); }
287         ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
288         ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
289
290         // expand/collect
291         ex expand(unsigned options=0) const;
292         ex collect(const ex & s, bool distributed = false) const { return bp->collect(s, distributed); }
293
294         // differentiation and series expansion
295         ex diff(const symbol & s, unsigned nth = 1) const;
296         ex series(const ex & r, int order, unsigned options = 0) const;
297
298         // rational functions
299         ex normal(int level = 0) const;
300         ex to_rational(lst &repl_lst) const;
301         ex to_polynomial(lst &repl_lst) const;
302         ex numer() const;
303         ex denom() const;
304         ex numer_denom() const;
305
306         // polynomial algorithms
307         ex unit(const symbol &x) const;
308         ex content(const symbol &x) const;
309         numeric integer_content() const;
310         ex primpart(const symbol &x) const;
311         ex primpart(const symbol &x, const ex &cont) const;
312         ex smod(const numeric &xi) const { return bp->smod(xi); }
313         numeric max_coefficient() const;
314
315         // indexed objects
316         exvector get_free_indices() const { return bp->get_free_indices(); }
317         ex simplify_indexed() const;
318         ex simplify_indexed(const scalar_products & sp) const;
319
320         // comparison
321         int compare(const ex & other) const;
322         bool is_equal(const ex & other) const;
323         bool is_zero() const { extern const ex _ex0; return is_equal(_ex0); }
324         
325         // symmetry
326         ex symmetrize() const;
327         ex symmetrize(const lst & l) const;
328         ex antisymmetrize() const;
329         ex antisymmetrize(const lst & l) const;
330         ex symmetrize_cyclic() const;
331         ex symmetrize_cyclic(const lst & l) const;
332
333         // noncommutativity
334         unsigned return_type() const { return bp->return_type(); }
335         unsigned return_type_tinfo() const { return bp->return_type_tinfo(); }
336
337         unsigned gethash() const { return bp->gethash(); }
338
339 private:
340         static ptr<basic> construct_from_basic(const basic & other);
341         static basic & construct_from_int(int i);
342         static basic & construct_from_uint(unsigned int i);
343         static basic & construct_from_long(long i);
344         static basic & construct_from_ulong(unsigned long i);
345         static basic & construct_from_double(double d);
346         static ptr<basic> construct_from_string_and_lst(const std::string &s, const ex &l);
347         void makewriteable();
348
349 #ifdef OBSCURE_CINT_HACK
350 public:
351         static bool last_created_or_assigned_bp_can_be_converted_to_ex()
352         {
353                 if (last_created_or_assigned_bp==0) return false;
354                 if ((last_created_or_assigned_bp->flags &
355                          status_flags::dynallocated)==0) return false;
356                 if ((last_created_or_assigned_bp->flags &
357                          status_flags::evaluated)==0) return false;
358                 return true;
359         }
360 protected:
361         void update_last_created_or_assigned_bp()
362         {
363                 last_created_or_assigned_bp = bp;
364                 last_created_or_assigned_exp = (long)(void *)(this);
365         }
366 #endif // def OBSCURE_CINT_HACK
367
368 // member variables
369
370 private:
371         ptr<basic> bp;      ///< pointer to basic object managed by this
372
373 #ifdef OBSCURE_CINT_HACK
374 public:
375         static ptr<basic> last_created_or_assigned_bp;
376         static basic * dummy_bp;
377         static long last_created_or_assigned_exp;
378 #endif // def OBSCURE_CINT_HACK
379 };
380
381
382 // performance-critical inlined method implementations
383
384 // This needs to be a basic* because we don't know that numeric is derived
385 // from basic and we need a basic& for the ex default constructor
386 extern const basic *_num0_bp;
387
388 inline
389 ex::ex() : bp(*const_cast<basic *>(_num0_bp))
390 {
391         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
392 #ifdef OBSCURE_CINT_HACK
393         update_last_created_or_assigned_bp();
394 #endif // def OBSCURE_CINT_HACK
395 }
396
397 #ifdef OBSCURE_CINT_HACK
398 inline
399 ex::ex(const ex & other) : bp(other.bp)
400 {
401         GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
402         update_last_created_or_assigned_bp();
403 }
404
405 inline
406 ex & ex::operator=(const ex & other)
407 {
408         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
409         GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
410         bp = other.bp;
411         update_last_created_or_assigned_bp();
412         return *this;
413 }
414 #endif // def OBSCURE_CINT_HACK
415
416 inline
417 ex::ex(const basic & other) : bp(construct_from_basic(other))
418 {
419         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
420 #ifdef OBSCURE_CINT_HACK
421         update_last_created_or_assigned_bp();
422 #endif // def OBSCURE_CINT_HACK
423 }
424
425 inline
426 ex::ex(int i) : bp(construct_from_int(i))
427 {
428         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
429 #ifdef OBSCURE_CINT_HACK
430         update_last_created_or_assigned_bp();
431 #endif // def OBSCURE_CINT_HACK
432 }
433
434 inline
435 ex::ex(unsigned int i) : bp(construct_from_uint(i))
436 {
437         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
438 #ifdef OBSCURE_CINT_HACK
439         update_last_created_or_assigned_bp();
440 #endif // def OBSCURE_CINT_HACK
441 }
442
443 inline
444 ex::ex(long i) : bp(construct_from_long(i))
445 {
446         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
447 #ifdef OBSCURE_CINT_HACK
448         update_last_created_or_assigned_bp();
449 #endif // def OBSCURE_CINT_HACK
450 }
451
452 inline
453 ex::ex(unsigned long i) : bp(construct_from_ulong(i))
454 {
455         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
456 #ifdef OBSCURE_CINT_HACK
457         update_last_created_or_assigned_bp();
458 #endif // def OBSCURE_CINT_HACK
459 }
460
461 inline
462 ex::ex(double const d) : bp(construct_from_double(d))
463 {
464         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
465 #ifdef OBSCURE_CINT_HACK
466         update_last_created_or_assigned_bp();
467 #endif // def OBSCURE_CINT_HACK
468 }
469
470 inline
471 ex::ex(const std::string &s, const ex &l) : bp(construct_from_string_and_lst(s, l))
472 {
473         GINAC_ASSERT(bp->flags & status_flags::dynallocated);
474 #ifdef OBSCURE_CINT_HACK
475         update_last_created_or_assigned_bp();
476 #endif // def OBSCURE_CINT_HACK
477 }
478
479 inline
480 int ex::compare(const ex & other) const
481 {
482         if (bp == other.bp)  // trivial case: both expressions point to same basic
483                 return 0;
484         return bp->compare(*other.bp);
485 }
486
487 inline
488 bool ex::is_equal(const ex & other) const
489 {
490         if (bp == other.bp)  // trivial case: both expressions point to same basic
491                 return true;
492         return bp->is_equal(*other.bp);
493 }
494
495
496 // utility functions
497
498 /** Compare two objects of class quickly without doing a deep tree traversal.
499  *  @return "true" if they are equal
500  *          "false" if equality cannot be established quickly (e1 and e2 may
501  *          still be equal, in this case. */
502 inline bool are_ex_trivially_equal(const ex &e1, const ex &e2)
503 {
504         return e1.bp == e2.bp;
505 }
506
507 // wrapper functions around member functions
508 inline size_t nops(const ex & thisex)
509 { return thisex.nops(); }
510
511 inline ex expand(const ex & thisex, unsigned options = 0)
512 { return thisex.expand(options); }
513
514 inline bool has(const ex & thisex, const ex & pattern)
515 { return thisex.has(pattern); }
516
517 inline bool find(const ex & thisex, const ex & pattern, lst & found)
518 { return thisex.find(pattern, found); }
519
520 inline int degree(const ex & thisex, const ex & s)
521 { return thisex.degree(s); }
522
523 inline int ldegree(const ex & thisex, const ex & s)
524 { return thisex.ldegree(s); }
525
526 inline ex coeff(const ex & thisex, const ex & s, int n=1)
527 { return thisex.coeff(s, n); }
528
529 inline ex numer(const ex & thisex)
530 { return thisex.numer(); }
531
532 inline ex denom(const ex & thisex)
533 { return thisex.denom(); }
534
535 inline ex numer_denom(const ex & thisex)
536 { return thisex.numer_denom(); }
537
538 inline ex normal(const ex & thisex, int level=0)
539 { return thisex.normal(level); }
540
541 inline ex to_rational(const ex & thisex, lst & repl_lst)
542 { return thisex.to_rational(repl_lst); }
543
544 inline ex to_polynomial(const ex & thisex, lst & repl_lst)
545 { return thisex.to_polynomial(repl_lst); }
546
547 inline ex collect(const ex & thisex, const ex & s, bool distributed = false)
548 { return thisex.collect(s, distributed); }
549
550 inline ex eval(const ex & thisex, int level = 0)
551 { return thisex.eval(level); }
552
553 inline ex evalf(const ex & thisex, int level = 0)
554 { return thisex.evalf(level); }
555
556 inline ex evalm(const ex & thisex)
557 { return thisex.evalm(); }
558
559 inline ex diff(const ex & thisex, const symbol & s, unsigned nth = 1)
560 { return thisex.diff(s, nth); }
561
562 inline ex series(const ex & thisex, const ex & r, int order, unsigned options = 0)
563 { return thisex.series(r, order, options); }
564
565 inline bool match(const ex & thisex, const ex & pattern, lst & repl_lst)
566 { return thisex.match(pattern, repl_lst); }
567
568 inline ex simplify_indexed(const ex & thisex)
569 { return thisex.simplify_indexed(); }
570
571 inline ex simplify_indexed(const ex & thisex, const scalar_products & sp)
572 { return thisex.simplify_indexed(sp); }
573
574 inline ex symmetrize(const ex & thisex)
575 { return thisex.symmetrize(); }
576
577 inline ex symmetrize(const ex & thisex, const lst & l)
578 { return thisex.symmetrize(l); }
579
580 inline ex antisymmetrize(const ex & thisex)
581 { return thisex.antisymmetrize(); }
582
583 inline ex antisymmetrize(const ex & thisex, const lst & l)
584 { return thisex.antisymmetrize(l); }
585
586 inline ex symmetrize_cyclic(const ex & thisex)
587 { return thisex.symmetrize_cyclic(); }
588
589 inline ex symmetrize_cyclic(const ex & thisex, const lst & l)
590 { return thisex.symmetrize_cyclic(l); }
591
592 inline ex op(const ex & thisex, size_t i)
593 { return thisex.op(i); }
594
595 inline ex lhs(const ex & thisex)
596 { return thisex.lhs(); }
597
598 inline ex rhs(const ex & thisex)
599 { return thisex.rhs(); }
600
601 inline bool is_zero(const ex & thisex)
602 { return thisex.is_zero(); }
603
604 inline void swap(ex & e1, ex & e2)
605 { e1.swap(e2); }
606
607 /* Function objects for STL sort() etc. */
608 struct ex_is_less : public std::binary_function<ex, ex, bool> {
609         bool operator() (const ex &lh, const ex &rh) const { return lh.compare(rh) < 0; }
610 };
611
612 struct ex_is_equal : public std::binary_function<ex, ex, bool> {
613         bool operator() (const ex &lh, const ex &rh) const { return lh.is_equal(rh); }
614 };
615
616 struct op0_is_equal : public std::binary_function<ex, ex, bool> {
617         bool operator() (const ex &lh, const ex &rh) const { return lh.op(0).is_equal(rh.op(0)); }
618 };
619
620 struct ex_swap : public std::binary_function<ex, ex, void> {
621         void operator() (ex &lh, ex &rh) const { lh.swap(rh); }
622 };
623
624 inline ex ex::subs(const exmap & m, unsigned options) const
625 {
626         return bp->subs(m, options);
627 }
628
629 inline ex subs(const ex & thisex, const exmap & m, unsigned options = 0)
630 { return thisex.subs(m, options); }
631
632 inline ex subs(const ex & thisex, const lst & ls, const lst & lr, unsigned options = 0)
633 { return thisex.subs(ls, lr, options); }
634
635 inline ex subs(const ex & thisex, const ex & e, unsigned options = 0)
636 { return thisex.subs(e, options); }
637
638
639 /* Convert function pointer to function object suitable for map(). */
640 class pointer_to_map_function : public map_function {
641 protected:
642         ex (*ptr)(const ex &);
643 public:
644         explicit pointer_to_map_function(ex x(const ex &)) : ptr(x) {}
645         ex operator()(const ex & e) { return ptr(e); }
646 };
647
648 template<class T1>
649 class pointer_to_map_function_1arg : public map_function {
650 protected:
651         ex (*ptr)(const ex &, T1);
652         T1 arg1;
653 public:
654         explicit pointer_to_map_function_1arg(ex x(const ex &, T1), T1 a1) : ptr(x), arg1(a1) {}
655         ex operator()(const ex & e) { return ptr(e, arg1); }
656 };
657
658 template<class T1, class T2>
659 class pointer_to_map_function_2args : public map_function {
660 protected:
661         ex (*ptr)(const ex &, T1, T2);
662         T1 arg1;
663         T2 arg2;
664 public:
665         explicit pointer_to_map_function_2args(ex x(const ex &, T1, T2), T1 a1, T2 a2) : ptr(x), arg1(a1), arg2(a2) {}
666         ex operator()(const ex & e) { return ptr(e, arg1, arg2); }
667 };
668
669 template<class T1, class T2, class T3>
670 class pointer_to_map_function_3args : public map_function {
671 protected:
672         ex (*ptr)(const ex &, T1, T2, T3);
673         T1 arg1;
674         T2 arg2;
675         T3 arg3;
676 public:
677         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) {}
678         ex operator()(const ex & e) { return ptr(e, arg1, arg2, arg3); }
679 };
680
681 inline ex ex::map(ex f(const ex &)) const
682 {
683         pointer_to_map_function fcn(f);
684         return bp->map(fcn);
685 }
686
687 // convenience type checker template functions
688
689 /** Check if ex is a handle to a T, including base classes. */
690 template <class T>
691 inline bool is_a(const ex &obj)
692 {
693         return is_a<T>(*obj.bp);
694 }
695
696 /** Check if ex is a handle to a T, not including base classes. */
697 template <class T>
698 inline bool is_exactly_a(const ex &obj)
699 {
700         return is_exactly_a<T>(*obj.bp);
701 }
702
703 /** Return a reference to the basic-derived class T object embedded in an
704  *  expression.  This is fast but unsafe: the result is undefined if the
705  *  expression does not contain a T object at its top level.  Hence, you
706  *  should generally check the type of e first.
707  *
708  *  @param e expression
709  *  @return reference to object of class T
710  *  @see is_exactly_a<class T>() */
711 template <class T>
712 inline const T &ex_to(const ex &e)
713 {
714         GINAC_ASSERT(is_a<T>(e));
715         return static_cast<const T &>(*e.bp);
716 }
717
718 } // namespace GiNaC
719
720
721 // Specializations of Standard Library algorithms
722 namespace std {
723
724 /** Specialization of std::swap() for ex objects. */
725 template <>
726 inline void swap(GiNaC::ex &a, GiNaC::ex &b)
727 {
728         a.swap(b);
729 }
730
731 /** Specialization of std::iter_swap() for vector<ex> iterators. */
732 template <>
733 inline void iter_swap(vector<GiNaC::ex>::iterator i1, vector<GiNaC::ex>::iterator i2)
734 {
735         i1->swap(*i2);
736 }
737
738 /** Specialization of std::iter_swap() for list<ex> iterators. */
739 template <>
740 inline void iter_swap(list<GiNaC::ex>::iterator i1, list<GiNaC::ex>::iterator i2)
741 {
742         i1->swap(*i2);
743 }
744
745 } // namespace std
746
747 #endif // ndef __GINAC_EX_H__