3 * Interface to GiNaC's light-weight expression handles. */
6 * GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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
45 static void init_unarchivers();
52 /** For construction of flyweights, etc. */
53 static library_init library_initializer;
55 class scalar_products;
57 class const_preorder_iterator;
58 class const_postorder_iterator;
61 /** Lightweight wrapper for GiNaC's symbolic objects. It holds a pointer to
62 * the other object in order to do garbage collection by the method of
63 * reference counting. I.e., it is a smart pointer. Also, the constructor
64 * ex::ex(const basic & other) calls the methods that do automatic
65 * evaluation. E.g., x-x turns automatically into 0. */
67 friend class archive_node;
68 friend inline bool are_ex_trivially_equal(const ex &, const ex &);
69 template<class T> friend inline const T &ex_to(const ex &);
70 template<class T> friend inline bool is_a(const ex &);
71 template<class T> friend inline bool is_exactly_a(const ex &);
73 // default constructor, copy constructor and assignment operator
79 ex(const basic & other);
86 /** Construct ex from string and a list of symbols. The input grammar is
87 * similar to the GiNaC output format. All symbols and indices to be used
88 * in the expression must be specified in a lst in the second argument.
89 * Undefined symbols and other parser errors will throw an exception. */
90 ex(const std::string &s, const ex &l);
93 // non-virtual functions in this class
95 /** Efficiently swap the contents of two expressions. */
96 void swap(ex & other) throw()
98 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
99 GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
104 const_iterator begin() const throw();
105 const_iterator end() const throw();
106 const_preorder_iterator preorder_begin() const;
107 const_preorder_iterator preorder_end() const throw();
108 const_postorder_iterator postorder_begin() const;
109 const_postorder_iterator postorder_end() const throw();
112 ex eval(int level = 0) const { return bp->eval(level); }
113 ex evalf(int level = 0) const { return bp->evalf(level); }
114 ex evalm() const { return bp->evalm(); }
115 ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); }
116 ex eval_integ() const { return bp->eval_integ(); }
119 void print(const print_context & c, unsigned level = 0) const;
120 void dbgprint() const;
121 void dbgprinttree() const;
124 bool info(unsigned inf) const { return bp->info(inf); }
127 size_t nops() const { return bp->nops(); }
128 ex op(size_t i) const { return bp->op(i); }
129 ex operator[](const ex & index) const { return (*bp)[index]; }
130 ex operator[](size_t i) const { return (*bp)[i]; }
131 ex & let_op(size_t i);
132 ex & operator[](const ex & index);
133 ex & operator[](size_t i);
137 // function for complex expressions
138 ex conjugate() const { return bp->conjugate(); }
139 ex real_part() const { return bp->real_part(); }
140 ex imag_part() const { return bp->imag_part(); }
143 bool has(const ex & pattern, unsigned options = 0) const { return bp->has(pattern, options); }
144 bool find(const ex & pattern, exset& found) const;
145 bool match(const ex & pattern) const;
146 bool match(const ex & pattern, exmap & repls) const { return bp->match(pattern, repls); }
149 ex subs(const exmap & m, unsigned options = 0) const;
150 ex subs(const lst & ls, const lst & lr, unsigned options = 0) const;
151 ex subs(const ex & e, unsigned options = 0) const;
154 ex map(map_function & f) const { return bp->map(f); }
155 ex map(ex (*f)(const ex & e)) const;
157 // visitors and tree traversal
158 void accept(visitor & v) const { bp->accept(v); }
159 void traverse_preorder(visitor & v) const;
160 void traverse_postorder(visitor & v) const;
161 void traverse(visitor & v) const { traverse_preorder(v); }
164 bool is_polynomial(const ex & vars) const;
165 int degree(const ex & s) const { return bp->degree(s); }
166 int ldegree(const ex & s) const { return bp->ldegree(s); }
167 ex coeff(const ex & s, int n = 1) const { return bp->coeff(s, n); }
168 ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
169 ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
172 ex expand(unsigned options=0) const;
173 ex collect(const ex & s, bool distributed = false) const { return bp->collect(s, distributed); }
175 // differentiation and series expansion
176 ex diff(const symbol & s, unsigned nth = 1) const;
177 ex series(const ex & r, int order, unsigned options = 0) const;
179 // rational functions
180 ex normal(int level = 0) const;
181 ex to_rational(exmap & repl) const;
182 ex to_rational(lst & repl_lst) const;
183 ex to_polynomial(exmap & repl) const;
184 ex to_polynomial(lst & repl_lst) const;
187 ex numer_denom() const;
189 // polynomial algorithms
190 ex unit(const ex &x) const;
191 ex content(const ex &x) const;
192 numeric integer_content() const;
193 ex primpart(const ex &x) const;
194 ex primpart(const ex &x, const ex &cont) const;
195 void unitcontprim(const ex &x, ex &u, ex &c, ex &p) const;
196 ex smod(const numeric &xi) const { return bp->smod(xi); }
197 numeric max_coefficient() const;
200 exvector get_free_indices() const { return bp->get_free_indices(); }
201 ex simplify_indexed(unsigned options = 0) const;
202 ex simplify_indexed(const scalar_products & sp, unsigned options = 0) const;
205 int compare(const ex & other) const;
206 bool is_equal(const ex & other) const;
207 bool is_zero() const { extern const ex _ex0; return is_equal(_ex0); }
208 bool is_zero_matrix() const;
211 ex symmetrize() const;
212 ex symmetrize(const lst & l) const;
213 ex antisymmetrize() const;
214 ex antisymmetrize(const lst & l) const;
215 ex symmetrize_cyclic() const;
216 ex symmetrize_cyclic(const lst & l) const;
219 unsigned return_type() const { return bp->return_type(); }
220 return_type_t return_type_tinfo() const { return bp->return_type_tinfo(); }
222 unsigned gethash() const { return bp->gethash(); }
225 static ptr<basic> construct_from_basic(const basic & other);
226 static basic & construct_from_int(int i);
227 static basic & construct_from_uint(unsigned int i);
228 static basic & construct_from_long(long i);
229 static basic & construct_from_ulong(unsigned long i);
230 static basic & construct_from_double(double d);
231 static ptr<basic> construct_from_string_and_lst(const std::string &s, const ex &l);
232 void makewriteable();
233 void share(const ex & other) const;
238 mutable ptr<basic> bp; ///< pointer to basic object managed by this
242 // performance-critical inlined method implementations
244 // This needs to be a basic* because we don't know that numeric is derived
245 // from basic and we need a basic& for the ex default constructor
246 extern const basic *_num0_bp;
249 ex::ex() throw() : bp(*const_cast<basic *>(_num0_bp))
251 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
255 ex::ex(const basic & other) : bp(construct_from_basic(other))
257 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
261 ex::ex(int i) : bp(construct_from_int(i))
263 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
267 ex::ex(unsigned int i) : bp(construct_from_uint(i))
269 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
273 ex::ex(long i) : bp(construct_from_long(i))
275 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
279 ex::ex(unsigned long i) : bp(construct_from_ulong(i))
281 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
285 ex::ex(double const d) : bp(construct_from_double(d))
287 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
291 ex::ex(const std::string &s, const ex &l) : bp(construct_from_string_and_lst(s, l))
293 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
297 int ex::compare(const ex & other) const
299 #ifdef GINAC_COMPARE_STATISTICS
300 compare_statistics.total_compares++;
302 if (bp == other.bp) // trivial case: both expressions point to same basic
304 #ifdef GINAC_COMPARE_STATISTICS
305 compare_statistics.nontrivial_compares++;
307 const int cmpval = bp->compare(*other.bp);
310 // Expressions point to different, but equal, trees: conserve
311 // memory and make subsequent compare() operations faster by
312 // making both expressions point to the same tree.
320 bool ex::is_equal(const ex & other) const
322 #ifdef GINAC_COMPARE_STATISTICS
323 compare_statistics.total_is_equals++;
325 if (bp == other.bp) // trivial case: both expressions point to same basic
327 #ifdef GINAC_COMPARE_STATISTICS
328 compare_statistics.nontrivial_is_equals++;
330 const bool equal = bp->is_equal(*other.bp);
333 // Expressions point to different, but equal, trees: conserve
334 // memory and make subsequent compare() operations faster by
335 // making both expressions point to the same tree.
345 class const_iterator : public std::iterator<std::random_access_iterator_tag, ex, ptrdiff_t, const ex *, const ex &> {
347 friend class const_preorder_iterator;
348 friend class const_postorder_iterator;
351 const_iterator() throw() {}
354 const_iterator(const ex &e_, size_t i_) throw() : e(e_), i(i_) {}
357 // This should return an ex&, but that would be a reference to a
364 // This should return an ex*, but that would be a pointer to a
366 std::auto_ptr<ex> operator->() const
368 return std::auto_ptr<ex>(new ex(operator*()));
371 ex operator[](difference_type n) const
376 const_iterator &operator++() throw()
382 const_iterator operator++(int) throw()
384 const_iterator tmp = *this;
389 const_iterator &operator+=(difference_type n) throw()
395 const_iterator operator+(difference_type n) const throw()
397 return const_iterator(e, i + n);
400 inline friend const_iterator operator+(difference_type n, const const_iterator &it) throw()
402 return const_iterator(it.e, it.i + n);
405 const_iterator &operator--() throw()
411 const_iterator operator--(int) throw()
413 const_iterator tmp = *this;
418 const_iterator &operator-=(difference_type n) throw()
424 const_iterator operator-(difference_type n) const throw()
426 return const_iterator(e, i - n);
429 inline friend difference_type operator-(const const_iterator &lhs, const const_iterator &rhs) throw()
431 return lhs.i - rhs.i;
434 bool operator==(const const_iterator &other) const throw()
436 return are_ex_trivially_equal(e, other.e) && i == other.i;
439 bool operator!=(const const_iterator &other) const throw()
441 return !(*this == other);
444 bool operator<(const const_iterator &other) const throw()
449 bool operator>(const const_iterator &other) const throw()
451 return other < *this;
454 bool operator<=(const const_iterator &other) const throw()
456 return !(other < *this);
459 bool operator>=(const const_iterator &other) const throw()
461 return !(*this < other);
465 ex e; // this used to be a "const basic *", but in view of object fusion that wouldn't be safe
472 _iter_rep(const ex &e_, size_t i_, size_t i_end_) : e(e_), i(i_), i_end(i_end_) {}
474 bool operator==(const _iter_rep &other) const throw()
476 return are_ex_trivially_equal(e, other.e) && i == other.i;
479 bool operator!=(const _iter_rep &other) const throw()
481 return !(*this == other);
489 } // namespace internal
491 class const_preorder_iterator : public std::iterator<std::forward_iterator_tag, ex, ptrdiff_t, const ex *, const ex &> {
493 const_preorder_iterator() throw() {}
495 const_preorder_iterator(const ex &e, size_t n)
497 s.push(internal::_iter_rep(e, 0, n));
501 reference operator*() const
506 pointer operator->() const
511 const_preorder_iterator &operator++()
517 const_preorder_iterator operator++(int)
519 const_preorder_iterator tmp = *this;
524 bool operator==(const const_preorder_iterator &other) const throw()
529 bool operator!=(const const_preorder_iterator &other) const throw()
531 return !(*this == other);
535 std::stack<internal::_iter_rep, std::vector<internal::_iter_rep> > s;
539 while (!s.empty() && s.top().i == s.top().i_end) {
546 internal::_iter_rep & current = s.top();
548 if (current.i != current.i_end) {
549 const ex & child = current.e.op(current.i);
550 s.push(internal::_iter_rep(child, 0, child.nops()));
555 class const_postorder_iterator : public std::iterator<std::forward_iterator_tag, ex, ptrdiff_t, const ex *, const ex &> {
557 const_postorder_iterator() throw() {}
559 const_postorder_iterator(const ex &e, size_t n)
561 s.push(internal::_iter_rep(e, 0, n));
566 reference operator*() const
571 pointer operator->() const
576 const_postorder_iterator &operator++()
582 const_postorder_iterator operator++(int)
584 const_postorder_iterator tmp = *this;
589 bool operator==(const const_postorder_iterator &other) const throw()
594 bool operator!=(const const_postorder_iterator &other) const throw()
596 return !(*this == other);
600 std::stack<internal::_iter_rep, std::vector<internal::_iter_rep> > s;
604 while (s.top().i != s.top().i_end) {
605 internal::_iter_rep & current = s.top();
606 const ex & child = current.e.op(current.i);
607 s.push(internal::_iter_rep(child, 0, child.nops()));
613 if (s.top().i == s.top().i_end)
622 inline const_iterator ex::begin() const throw()
624 return const_iterator(*this, 0);
627 inline const_iterator ex::end() const throw()
629 return const_iterator(*this, nops());
632 inline const_preorder_iterator ex::preorder_begin() const
634 return const_preorder_iterator(*this, nops());
637 inline const_preorder_iterator ex::preorder_end() const throw()
639 return const_preorder_iterator();
642 inline const_postorder_iterator ex::postorder_begin() const
644 return const_postorder_iterator(*this, nops());
647 inline const_postorder_iterator ex::postorder_end() const throw()
649 return const_postorder_iterator();
655 /** Compare two objects of class quickly without doing a deep tree traversal.
656 * @return "true" if they are equal
657 * "false" if equality cannot be established quickly (e1 and e2 may
658 * still be equal, in this case. */
659 inline bool are_ex_trivially_equal(const ex &e1, const ex &e2)
661 return e1.bp == e2.bp;
664 /* Function objects for STL sort() etc. */
665 struct ex_is_less : public std::binary_function<ex, ex, bool> {
666 bool operator() (const ex &lh, const ex &rh) const { return lh.compare(rh) < 0; }
669 struct ex_is_equal : public std::binary_function<ex, ex, bool> {
670 bool operator() (const ex &lh, const ex &rh) const { return lh.is_equal(rh); }
673 struct op0_is_equal : public std::binary_function<ex, ex, bool> {
674 bool operator() (const ex &lh, const ex &rh) const { return lh.op(0).is_equal(rh.op(0)); }
677 struct ex_swap : public std::binary_function<ex, ex, void> {
678 void operator() (ex &lh, ex &rh) const { lh.swap(rh); }
681 // Make it possible to print exvectors and exmaps
682 std::ostream & operator<<(std::ostream & os, const exvector & e);
683 std::ostream & operator<<(std::ostream & os, const exset & e);
684 std::ostream & operator<<(std::ostream & os, const exmap & e);
686 // wrapper functions around member functions
687 inline size_t nops(const ex & thisex)
688 { return thisex.nops(); }
690 inline ex expand(const ex & thisex, unsigned options = 0)
691 { return thisex.expand(options); }
693 inline ex conjugate(const ex & thisex)
694 { return thisex.conjugate(); }
696 inline ex real_part(const ex & thisex)
697 { return thisex.real_part(); }
699 inline ex imag_part(const ex & thisex)
700 { return thisex.imag_part(); }
702 inline bool has(const ex & thisex, const ex & pattern, unsigned options = 0)
703 { return thisex.has(pattern, options); }
705 inline bool find(const ex & thisex, const ex & pattern, exset& found)
706 { return thisex.find(pattern, found); }
708 inline bool is_polynomial(const ex & thisex, const ex & vars)
709 { return thisex.is_polynomial(vars); }
711 inline int degree(const ex & thisex, const ex & s)
712 { return thisex.degree(s); }
714 inline int ldegree(const ex & thisex, const ex & s)
715 { return thisex.ldegree(s); }
717 inline ex coeff(const ex & thisex, const ex & s, int n=1)
718 { return thisex.coeff(s, n); }
720 inline ex numer(const ex & thisex)
721 { return thisex.numer(); }
723 inline ex denom(const ex & thisex)
724 { return thisex.denom(); }
726 inline ex numer_denom(const ex & thisex)
727 { return thisex.numer_denom(); }
729 inline ex normal(const ex & thisex, int level=0)
730 { return thisex.normal(level); }
732 inline ex to_rational(const ex & thisex, lst & repl_lst)
733 { return thisex.to_rational(repl_lst); }
735 inline ex to_rational(const ex & thisex, exmap & repl)
736 { return thisex.to_rational(repl); }
738 inline ex to_polynomial(const ex & thisex, exmap & repl)
739 { return thisex.to_polynomial(repl); }
741 inline ex to_polynomial(const ex & thisex, lst & repl_lst)
742 { return thisex.to_polynomial(repl_lst); }
744 inline ex collect(const ex & thisex, const ex & s, bool distributed = false)
745 { return thisex.collect(s, distributed); }
747 inline ex eval(const ex & thisex, int level = 0)
748 { return thisex.eval(level); }
750 inline ex evalf(const ex & thisex, int level = 0)
751 { return thisex.evalf(level); }
753 inline ex evalm(const ex & thisex)
754 { return thisex.evalm(); }
756 inline ex eval_integ(const ex & thisex)
757 { return thisex.eval_integ(); }
759 inline ex diff(const ex & thisex, const symbol & s, unsigned nth = 1)
760 { return thisex.diff(s, nth); }
762 inline ex series(const ex & thisex, const ex & r, int order, unsigned options = 0)
763 { return thisex.series(r, order, options); }
765 inline bool match(const ex & thisex, const ex & pattern, exmap& repl_lst)
766 { return thisex.match(pattern, repl_lst); }
768 inline ex simplify_indexed(const ex & thisex, unsigned options = 0)
769 { return thisex.simplify_indexed(options); }
771 inline ex simplify_indexed(const ex & thisex, const scalar_products & sp, unsigned options = 0)
772 { return thisex.simplify_indexed(sp, options); }
774 inline ex symmetrize(const ex & thisex)
775 { return thisex.symmetrize(); }
777 inline ex symmetrize(const ex & thisex, const lst & l)
778 { return thisex.symmetrize(l); }
780 inline ex antisymmetrize(const ex & thisex)
781 { return thisex.antisymmetrize(); }
783 inline ex antisymmetrize(const ex & thisex, const lst & l)
784 { return thisex.antisymmetrize(l); }
786 inline ex symmetrize_cyclic(const ex & thisex)
787 { return thisex.symmetrize_cyclic(); }
789 inline ex symmetrize_cyclic(const ex & thisex, const lst & l)
790 { return thisex.symmetrize_cyclic(l); }
792 inline ex op(const ex & thisex, size_t i)
793 { return thisex.op(i); }
795 inline ex lhs(const ex & thisex)
796 { return thisex.lhs(); }
798 inline ex rhs(const ex & thisex)
799 { return thisex.rhs(); }
801 inline bool is_zero(const ex & thisex)
802 { return thisex.is_zero(); }
804 inline void swap(ex & e1, ex & e2)
807 inline ex ex::subs(const exmap & m, unsigned options) const
809 return bp->subs(m, options);
812 inline ex subs(const ex & thisex, const exmap & m, unsigned options = 0)
813 { return thisex.subs(m, options); }
815 inline ex subs(const ex & thisex, const lst & ls, const lst & lr, unsigned options = 0)
816 { return thisex.subs(ls, lr, options); }
818 inline ex subs(const ex & thisex, const ex & e, unsigned options = 0)
819 { return thisex.subs(e, options); }
822 /* Convert function pointer to function object suitable for map(). */
823 class pointer_to_map_function : public map_function {
825 ex (*ptr)(const ex &);
827 explicit pointer_to_map_function(ex x(const ex &)) : ptr(x) {}
828 ex operator()(const ex & e) { return ptr(e); }
832 class pointer_to_map_function_1arg : public map_function {
834 ex (*ptr)(const ex &, T1);
837 explicit pointer_to_map_function_1arg(ex x(const ex &, T1), T1 a1) : ptr(x), arg1(a1) {}
838 ex operator()(const ex & e) { return ptr(e, arg1); }
841 template<class T1, class T2>
842 class pointer_to_map_function_2args : public map_function {
844 ex (*ptr)(const ex &, T1, T2);
848 explicit pointer_to_map_function_2args(ex x(const ex &, T1, T2), T1 a1, T2 a2) : ptr(x), arg1(a1), arg2(a2) {}
849 ex operator()(const ex & e) { return ptr(e, arg1, arg2); }
852 template<class T1, class T2, class T3>
853 class pointer_to_map_function_3args : public map_function {
855 ex (*ptr)(const ex &, T1, T2, T3);
860 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) {}
861 ex operator()(const ex & e) { return ptr(e, arg1, arg2, arg3); }
865 class pointer_to_member_to_map_function : public map_function {
867 ex (C::*ptr)(const ex &);
870 explicit pointer_to_member_to_map_function(ex (C::*member)(const ex &), C &obj) : ptr(member), c(obj) {}
871 ex operator()(const ex & e) { return (c.*ptr)(e); }
874 template<class C, class T1>
875 class pointer_to_member_to_map_function_1arg : public map_function {
877 ex (C::*ptr)(const ex &, T1);
881 explicit pointer_to_member_to_map_function_1arg(ex (C::*member)(const ex &, T1), C &obj, T1 a1) : ptr(member), c(obj), arg1(a1) {}
882 ex operator()(const ex & e) { return (c.*ptr)(e, arg1); }
885 template<class C, class T1, class T2>
886 class pointer_to_member_to_map_function_2args : public map_function {
888 ex (C::*ptr)(const ex &, T1, T2);
893 explicit pointer_to_member_to_map_function_2args(ex (C::*member)(const ex&, T1, T2), C &obj, T1 a1, T2 a2) : ptr(member), c(obj), arg1(a1), arg2(a2) {}
894 ex operator()(const ex & e) { return (c.*ptr)(e, arg1, arg2); }
897 template<class C, class T1, class T2, class T3>
898 class pointer_to_member_to_map_function_3args : public map_function {
900 ex (C::*ptr)(const ex &, T1, T2, T3);
906 explicit pointer_to_member_to_map_function_3args(ex (C::*member)(const ex &, T1, T2, T3), C &obj, T1 a1, T2 a2, T3 a3) : ptr(member), c(obj), arg1(a1), arg2(a2), arg3(a3) {}
907 ex operator()(const ex & e) { return (c.*ptr)(e, arg1, arg2, arg3); }
910 inline ex ex::map(ex f(const ex &)) const
912 pointer_to_map_function fcn(f);
916 // convenience type checker template functions
918 /** Check if ex is a handle to a T, including base classes. */
920 inline bool is_a(const ex &obj)
922 return is_a<T>(*obj.bp);
925 /** Check if ex is a handle to a T, not including base classes. */
927 inline bool is_exactly_a(const ex &obj)
929 return is_exactly_a<T>(*obj.bp);
932 /** Return a reference to the basic-derived class T object embedded in an
933 * expression. This is fast but unsafe: the result is undefined if the
934 * expression does not contain a T object at its top level. Hence, you
935 * should generally check the type of e first. Also, you shouldn't cache
936 * the returned reference because GiNaC's garbage collector may destroy
937 * the referenced object any time it's used in another expression.
939 * @param e expression
940 * @return reference to object of class T
941 * @see is_exactly_a<class T>() */
943 inline const T &ex_to(const ex &e)
945 GINAC_ASSERT(is_a<T>(e));
946 return static_cast<const T &>(*e.bp);
952 // Specializations of Standard Library algorithms
955 /** Specialization of std::swap() for ex objects. */
957 inline void swap(GiNaC::ex &a, GiNaC::ex &b)
962 /** Specialization of std::iter_swap() for vector<ex> iterators. */
964 inline void iter_swap(vector<GiNaC::ex>::iterator i1, vector<GiNaC::ex>::iterator i2)
969 /** Specialization of std::iter_swap() for list<ex> iterators. */
971 inline void iter_swap(list<GiNaC::ex>::iterator i1, list<GiNaC::ex>::iterator i2)
978 #endif // ndef GINAC_EX_H