]> www.ginac.de Git - ginac.git/commitdiff
generous use of auto_ptr to provide better exception safety and make the code
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 26 Aug 2003 20:57:44 +0000 (20:57 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 26 Aug 2003 20:57:44 +0000 (20:57 +0000)
more expressive (doesn't that sound great?)

18 files changed:
ginac/add.cpp
ginac/add.h
ginac/clifford.cpp
ginac/clifford.h
ginac/color.cpp
ginac/color.h
ginac/container.h
ginac/expairseq.cpp
ginac/expairseq.h
ginac/fderivative.cpp
ginac/fderivative.h
ginac/function.pl
ginac/indexed.cpp
ginac/indexed.h
ginac/mul.cpp
ginac/mul.h
ginac/ncmul.cpp
ginac/ncmul.h

index 3dcdf2cc4a7bc3733d49cef210230bbb0e2086b9..cb6c8031ec21f7d3f18826f3974c3ba226255f4d 100644 (file)
@@ -86,13 +86,12 @@ add::add(const epvector & v, const ex & oc)
        GINAC_ASSERT(is_canonical());
 }
 
        GINAC_ASSERT(is_canonical());
 }
 
-add::add(epvector * vp, const ex & oc)
+add::add(std::auto_ptr<epvector> vp, const ex & oc)
 {
        tinfo_key = TINFO_add;
        GINAC_ASSERT(vp!=0);
        overall_coeff = oc;
        construct_from_epvector(*vp);
 {
        tinfo_key = TINFO_add;
        GINAC_ASSERT(vp!=0);
        overall_coeff = oc;
        construct_from_epvector(*vp);
-       delete vp;
        GINAC_ASSERT(is_canonical());
 }
 
        GINAC_ASSERT(is_canonical());
 }
 
@@ -291,7 +290,7 @@ int add::ldegree(const ex & s) const
 
 ex add::coeff(const ex & s, int n) const
 {
 
 ex add::coeff(const ex & s, int n) const
 {
-       epvector *coeffseq = new epvector();
+       std::auto_ptr<epvector> coeffseq(new epvector);
 
        // Calculate sum of coefficients in each term
        epvector::const_iterator i = seq.begin(), end = seq.end();
 
        // Calculate sum of coefficients in each term
        epvector::const_iterator i = seq.begin(), end = seq.end();
@@ -314,8 +313,8 @@ ex add::coeff(const ex & s, int n) const
  *  @param level cut-off in recursive evaluation */
 ex add::eval(int level) const
 {
  *  @param level cut-off in recursive evaluation */
 ex add::eval(int level) const
 {
-       epvector *evaled_seqp = evalchildren(level);
-       if (evaled_seqp) {
+       std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
+       if (evaled_seqp.get()) {
                // do more evaluation later
                return (new add(evaled_seqp, overall_coeff))->
                       setflag(status_flags::dynallocated);
                // do more evaluation later
                return (new add(evaled_seqp, overall_coeff))->
                       setflag(status_flags::dynallocated);
@@ -355,7 +354,7 @@ ex add::evalm() const
 {
        // Evaluate children first and add up all matrices. Stop if there's one
        // term that is not a matrix.
 {
        // Evaluate children first and add up all matrices. Stop if there's one
        // term that is not a matrix.
-       epvector *s = new epvector;
+       std::auto_ptr<epvector> s(new epvector);
        s->reserve(seq.size());
 
        bool all_matrices = true;
        s->reserve(seq.size());
 
        bool all_matrices = true;
@@ -377,10 +376,9 @@ ex add::evalm() const
                ++it;
        }
 
                ++it;
        }
 
-       if (all_matrices) {
-               delete s;
+       if (all_matrices)
                return sum + overall_coeff;
                return sum + overall_coeff;
-       else
+       else
                return (new add(s, overall_coeff))->setflag(status_flags::dynallocated);
 }
 
                return (new add(s, overall_coeff))->setflag(status_flags::dynallocated);
 }
 
@@ -398,7 +396,7 @@ ex add::eval_ncmul(const exvector & v) const
  *  @see ex::diff */
 ex add::derivative(const symbol & y) const
 {
  *  @see ex::diff */
 ex add::derivative(const symbol & y) const
 {
-       epvector *s = new epvector();
+       std::auto_ptr<epvector> s(new epvector);
        s->reserve(seq.size());
        
        // Only differentiate the "rest" parts of the expairs. This is faster
        s->reserve(seq.size());
        
        // Only differentiate the "rest" parts of the expairs. This is faster
@@ -438,7 +436,7 @@ ex add::thisexpairseq(const epvector & v, const ex & oc) const
        return (new add(v,oc))->setflag(status_flags::dynallocated);
 }
 
        return (new add(v,oc))->setflag(status_flags::dynallocated);
 }
 
-ex add::thisexpairseq(epvector * vp, const ex & oc) const
+ex add::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const
 {
        return (new add(vp,oc))->setflag(status_flags::dynallocated);
 }
 {
        return (new add(vp,oc))->setflag(status_flags::dynallocated);
 }
@@ -508,8 +506,8 @@ ex add::recombine_pair_to_ex(const expair & p) const
 
 ex add::expand(unsigned options) const
 {
 
 ex add::expand(unsigned options) const
 {
-       epvector *vp = expandchildren(options);
-       if (vp == NULL) {
+       std::auto_ptr<epvector> vp = expandchildren(options);
+       if (vp.get() == 0) {
                // the terms have not changed, so it is safe to declare this expanded
                return (options == 0) ? setflag(status_flags::expanded) : *this;
        }
                // the terms have not changed, so it is safe to declare this expanded
                return (options == 0) ? setflag(status_flags::expanded) : *this;
        }
index d636d0ad1026f272c8721443a9d2e9cad7cc9627..f4862c58cfeb6c3375e0795a52c816a93dd1df4e 100644 (file)
@@ -41,7 +41,7 @@ public:
        add(const exvector & v);
        add(const epvector & v);
        add(const epvector & v, const ex & oc);
        add(const exvector & v);
        add(const epvector & v);
        add(const epvector & v, const ex & oc);
-       add(epvector * vp, const ex & oc);
+       add(std::auto_ptr<epvector> vp, const ex & oc);
        
        // functions overriding virtual functions from base classes
 public:
        
        // functions overriding virtual functions from base classes
 public:
@@ -64,7 +64,7 @@ protected:
        unsigned return_type() const;
        unsigned return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc) const;
        unsigned return_type() const;
        unsigned return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc) const;
-       ex thisexpairseq(epvector * vp, const ex & oc) const;
+       ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const;
        expair split_ex_to_pair(const ex & e) const;
        expair combine_ex_with_coeff_to_pair(const ex & e,
                                             const ex & c) const;
        expair split_ex_to_pair(const ex & e) const;
        expair combine_ex_with_coeff_to_pair(const ex & e,
                                             const ex & c) const;
index 3dbad50fd469deac73351de40555baedd43acf6b..717e444c41a5c39ac03deee33718447f25602ecc 100644 (file)
@@ -104,7 +104,7 @@ clifford::clifford(unsigned char rl, const exvector & v, bool discardable) : inh
        tinfo_key = TINFO_clifford;
 }
 
        tinfo_key = TINFO_clifford;
 }
 
-clifford::clifford(unsigned char rl, exvector * vp) : inherited(sy_none(), vp), representation_label(rl)
+clifford::clifford(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(sy_none(), vp), representation_label(rl)
 {
        tinfo_key = TINFO_clifford;
 }
 {
        tinfo_key = TINFO_clifford;
 }
@@ -479,7 +479,7 @@ ex clifford::thiscontainer(const exvector & v) const
        return clifford(representation_label, v);
 }
 
        return clifford(representation_label, v);
 }
 
-ex clifford::thiscontainer(exvector * vp) const
+ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
 {
        return clifford(representation_label, vp);
 }
 {
        return clifford(representation_label, vp);
 }
index eebe5e1f5ac34ba16811505606e791872b61b5d1..f551abb71febcd2936d444bc74f51612edf38f46 100644 (file)
@@ -45,14 +45,14 @@ public:
 
        // internal constructors
        clifford(unsigned char rl, const exvector & v, bool discardable = false);
 
        // internal constructors
        clifford(unsigned char rl, const exvector & v, bool discardable = false);
-       clifford(unsigned char rl, exvector * vp); // vp will be deleted
+       clifford(unsigned char rl, std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        ex thiscontainer(const exvector & v) const;
 
        // functions overriding virtual functions from base classes
 protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::noncommutative; }
        unsigned return_type_tinfo() const { return TINFO_clifford + representation_label; }
 
        unsigned return_type() const { return return_types::noncommutative; }
        unsigned return_type_tinfo() const { return TINFO_clifford + representation_label; }
 
index e84dcdba140a82e3a18a832747c6f0f909ce9fed..9a364c4395427198a842d765c0c057e34a6200b0 100644 (file)
@@ -94,7 +94,7 @@ color::color(unsigned char rl, const exvector & v, bool discardable) : inherited
        tinfo_key = TINFO_color;
 }
 
        tinfo_key = TINFO_color;
 }
 
-color::color(unsigned char rl, exvector * vp) : inherited(sy_none(), vp), representation_label(rl)
+color::color(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(sy_none(), vp), representation_label(rl)
 {
        tinfo_key = TINFO_color;
 }
 {
        tinfo_key = TINFO_color;
 }
@@ -183,7 +183,7 @@ ex color::thiscontainer(const exvector & v) const
        return color(representation_label, v);
 }
 
        return color(representation_label, v);
 }
 
-ex color::thiscontainer(exvector * vp) const
+ex color::thiscontainer(std::auto_ptr<exvector> vp) const
 {
        return color(representation_label, vp);
 }
 {
        return color(representation_label, vp);
 }
index 3af0c5c2cf7c81a5af3e4648ec65a49c58cb3790..8ff75442fa608de3dfe2c58861450837973314fc 100644 (file)
@@ -47,14 +47,14 @@ public:
 
        // internal constructors
        color(unsigned char rl, const exvector & v, bool discardable = false);
 
        // internal constructors
        color(unsigned char rl, const exvector & v, bool discardable = false);
-       color(unsigned char rl, exvector * vp); // vp will be deleted
+       color(unsigned char rl, std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        ex thiscontainer(const exvector & v) const;
 
        // functions overriding virtual functions from base classes
 protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::noncommutative; }
        unsigned return_type_tinfo() const { return TINFO_color + representation_label; }
 
        unsigned return_type() const { return return_types::noncommutative; }
        unsigned return_type_tinfo() const { return TINFO_color + representation_label; }
 
index c6a72e276d9226d76c06fe492a9879aa664248e3..e3465c46decb803392b255cc1c364c5df9b51d08 100644 (file)
@@ -28,6 +28,7 @@
 #include <algorithm>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <vector>
 #include <list>
+#include <memory>
 
 #include "ex.h"
 #include "print.h"
 
 #include "ex.h"
 #include "print.h"
@@ -93,15 +94,9 @@ public:
                        this->seq = s;
        }
 
                        this->seq = s;
        }
 
-       explicit container(STLT * vp) : inherited(get_tinfo())
+       explicit container(std::auto_ptr<STLT> vp) : inherited(get_tinfo())
        {
        {
-               if (vp == 0) {
-                       // lst(0) ends up here
-                       this->seq.push_back(0);
-               } else {
-                       this->seq.swap(*vp);
-                       delete vp;
-               }
+               this->seq.swap(*vp);
        }
 
        container(exvector::const_iterator b, exvector::const_iterator e)
        }
 
        container(exvector::const_iterator b, exvector::const_iterator e)
@@ -291,7 +286,7 @@ protected:
 
        /** Similar to duplicate(), but with a preset sequence (which gets
         *  deleted). Must be overridden by derived classes. */
 
        /** Similar to duplicate(), but with a preset sequence (which gets
         *  deleted). Must be overridden by derived classes. */
-       virtual ex thiscontainer(STLT * vp) const { return container(vp); }
+       virtual ex thiscontainer(std::auto_ptr<STLT> vp) const { return container(vp); }
 
        virtual void printseq(const print_context & c, char openbracket, char delim,
                              char closebracket, unsigned this_precedence,
 
        virtual void printseq(const print_context & c, char openbracket, char delim,
                              char closebracket, unsigned this_precedence,
@@ -335,7 +330,7 @@ protected:
        void do_print_python(const print_python & c, unsigned level) const;
        void do_print_python_repr(const print_python_repr & c, unsigned level) const;
        STLT evalchildren(int level) const;
        void do_print_python(const print_python & c, unsigned level) const;
        void do_print_python_repr(const print_python_repr & c, unsigned level) const;
        STLT evalchildren(int level) const;
-       STLT *subschildren(const exmap & m, unsigned options = 0) const;
+       std::auto_ptr<STLT> subschildren(const exmap & m, unsigned options = 0) const;
 };
 
 /** Default constructor */
 };
 
 /** Default constructor */
@@ -442,8 +437,8 @@ ex container<C>::eval(int level) const
 template <template <class> class C>
 ex container<C>::subs(const exmap & m, unsigned options) const
 {
 template <template <class> class C>
 ex container<C>::subs(const exmap & m, unsigned options) const
 {
-       STLT *vp = subschildren(m, options);
-       if (vp)
+       std::auto_ptr<STLT> vp = subschildren(m, options);
+       if (vp.get())
                return ex_to<basic>(thiscontainer(vp)).subs_one_level(m, options);
        else
                return subs_one_level(m, options);
                return ex_to<basic>(thiscontainer(vp)).subs_one_level(m, options);
        else
                return subs_one_level(m, options);
@@ -603,11 +598,11 @@ typename container<C>::STLT container<C>::evalchildren(int level) const
 }
 
 template <template <class> class C>
 }
 
 template <template <class> class C>
-typename container<C>::STLT *container<C>::subschildren(const exmap & m, unsigned options) const
+std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exmap & m, unsigned options) const
 {
        // returns a NULL pointer if nothing had to be substituted
        // returns a pointer to a newly created epvector otherwise
 {
        // returns a NULL pointer if nothing had to be substituted
        // returns a pointer to a newly created epvector otherwise
-       // (which has to be deleted somewhere else)
+       // (and relinquishes responsibility for the epvector)
 
        const_iterator cit = this->seq.begin(), end = this->seq.end();
        while (cit != end) {
 
        const_iterator cit = this->seq.begin(), end = this->seq.end();
        while (cit != end) {
@@ -615,7 +610,7 @@ typename container<C>::STLT *container<C>::subschildren(const exmap & m, unsigne
                if (!are_ex_trivially_equal(*cit, subsed_ex)) {
 
                        // copy first part of seq which hasn't changed
                if (!are_ex_trivially_equal(*cit, subsed_ex)) {
 
                        // copy first part of seq which hasn't changed
-                       STLT *s = new STLT(this->seq.begin(), cit);
+                       std::auto_ptr<STLT> s(new STLT(this->seq.begin(), cit));
                        reserve(*s, this->seq.size());
 
                        // insert changed element
                        reserve(*s, this->seq.size());
 
                        // insert changed element
@@ -634,7 +629,7 @@ typename container<C>::STLT *container<C>::subschildren(const exmap & m, unsigne
                ++cit;
        }
        
                ++cit;
        }
        
-       return 0; // nothing has changed
+       return std::auto_ptr<STLT>(0); // nothing has changed
 }
 
 } // namespace GiNaC
 }
 
 } // namespace GiNaC
index 24e2b5602d6e6dfe0c196f22ef220acdb3338133..88f195c8b04d25b48343e3d1b25ca14b0798b700 100644 (file)
@@ -125,13 +125,12 @@ expairseq::expairseq(const epvector &v, const ex &oc)
        GINAC_ASSERT(is_canonical());
 }
 
        GINAC_ASSERT(is_canonical());
 }
 
-expairseq::expairseq(epvector *vp, const ex &oc)
+expairseq::expairseq(std::auto_ptr<epvector> vp, const ex &oc)
   : inherited(TINFO_expairseq), overall_coeff(oc)
 {
        GINAC_ASSERT(vp!=0);
        GINAC_ASSERT(is_a<numeric>(oc));
        construct_from_epvector(*vp);
   : inherited(TINFO_expairseq), overall_coeff(oc)
 {
        GINAC_ASSERT(vp!=0);
        GINAC_ASSERT(is_a<numeric>(oc));
        construct_from_epvector(*vp);
-       delete vp;
        GINAC_ASSERT(is_canonical());
 }
 
        GINAC_ASSERT(is_canonical());
 }
 
@@ -283,7 +282,7 @@ ex expairseq::op(size_t i) const
 
 ex expairseq::map(map_function &f) const
 {
 
 ex expairseq::map(map_function &f) const
 {
-       epvector *v = new epvector;
+       std::auto_ptr<epvector> v(new epvector);
        v->reserve(seq.size());
 
        epvector::const_iterator cit = seq.begin(), last = seq.end();
        v->reserve(seq.size());
 
        epvector::const_iterator cit = seq.begin(), last = seq.end();
@@ -304,11 +303,11 @@ ex expairseq::eval(int level) const
        if ((level==1) && (flags &status_flags::evaluated))
                return *this;
        
        if ((level==1) && (flags &status_flags::evaluated))
                return *this;
        
-       epvector *vp = evalchildren(level);
-       if (vp==0)
+       std::auto_ptr<epvector> vp = evalchildren(level);
+       if (vp.get() == 0)
                return this->hold();
        
                return this->hold();
        
-       return (new expairseq(vp,overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
+       return (new expairseq(vp, overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
 }
 
 bool expairseq::match(const ex & pattern, lst & repl_lst) const
 }
 
 bool expairseq::match(const ex & pattern, lst & repl_lst) const
@@ -363,7 +362,7 @@ found:              ;
                        // it has already been matched before, in which case the matches
                        // must be equal)
                        size_t num = ops.size();
                        // it has already been matched before, in which case the matches
                        // must be equal)
                        size_t num = ops.size();
-                       epvector *vp = new epvector();
+                       std::auto_ptr<epvector> vp(new epvector);
                        vp->reserve(num);
                        for (size_t i=0; i<num; i++)
                                vp->push_back(split_ex_to_pair(ops[i]));
                        vp->reserve(num);
                        for (size_t i=0; i<num; i++)
                                vp->push_back(split_ex_to_pair(ops[i]));
@@ -387,8 +386,8 @@ found:              ;
 
 ex expairseq::subs(const exmap & m, unsigned options) const
 {
 
 ex expairseq::subs(const exmap & m, unsigned options) const
 {
-       epvector *vp = subschildren(m, options);
-       if (vp)
+       std::auto_ptr<epvector> vp = subschildren(m, options);
+       if (vp.get())
                return ex_to<basic>(thisexpairseq(vp, overall_coeff));
        else if ((options & subs_options::algebraic) && is_exactly_a<mul>(*this))
                return static_cast<const mul *>(this)->algebraic_subs_mul(m, options);
                return ex_to<basic>(thisexpairseq(vp, overall_coeff));
        else if ((options & subs_options::algebraic) && is_exactly_a<mul>(*this))
                return static_cast<const mul *>(this)->algebraic_subs_mul(m, options);
@@ -561,12 +560,13 @@ unsigned expairseq::calchash() const
 
 ex expairseq::expand(unsigned options) const
 {
 
 ex expairseq::expand(unsigned options) const
 {
-       epvector *vp = expandchildren(options);
-       if (vp == NULL) {
+       std::auto_ptr<epvector> vp = expandchildren(options);
+       if (vp.get())
+               return thisexpairseq(vp, overall_coeff);
+       else {
                // The terms have not changed, so it is safe to declare this expanded
                return (options == 0) ? setflag(status_flags::expanded) : *this;
                // The terms have not changed, so it is safe to declare this expanded
                return (options == 0) ? setflag(status_flags::expanded) : *this;
-       } else
-               return thisexpairseq(vp, overall_coeff);
+       }
 }
 
 //////////
 }
 
 //////////
@@ -585,12 +585,12 @@ ex expairseq::expand(unsigned options) const
  *  definition. */
 ex expairseq::thisexpairseq(const epvector &v, const ex &oc) const
 {
  *  definition. */
 ex expairseq::thisexpairseq(const epvector &v, const ex &oc) const
 {
-       return expairseq(v,oc);
+       return expairseq(v, oc);
 }
 
 }
 
-ex expairseq::thisexpairseq(epvector *vp, const ex &oc) const
+ex expairseq::thisexpairseq(std::auto_ptr<epvector> vp, const ex &oc) const
 {
 {
-       return expairseq(vp,oc);
+       return expairseq(vp, oc);
 }
 
 void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const
 }
 
 void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const
@@ -1450,7 +1450,7 @@ bool expairseq::is_canonical() const
  *  @see expairseq::expand()
  *  @return pointer to epvector containing expanded pairs or zero pointer,
  *  if no members were changed. */
  *  @see expairseq::expand()
  *  @return pointer to epvector containing expanded pairs or zero pointer,
  *  if no members were changed. */
-epvector * expairseq::expandchildren(unsigned options) const
+std::auto_ptr<epvector> expairseq::expandchildren(unsigned options) const
 {
        const epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
 {
        const epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
@@ -1459,7 +1459,7 @@ epvector * expairseq::expandchildren(unsigned options) const
                if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
                        
                        // something changed, copy seq, eval and return it
                if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
                        
                        // something changed, copy seq, eval and return it
-                       epvector *s = new epvector;
+                       std::auto_ptr<epvector> s(new epvector);
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
@@ -1468,10 +1468,12 @@ epvector * expairseq::expandchildren(unsigned options) const
                                s->push_back(*cit2);
                                ++cit2;
                        }
                                s->push_back(*cit2);
                                ++cit2;
                        }
+
                        // copy first changed element
                        s->push_back(combine_ex_with_coeff_to_pair(expanded_ex,
                                                                   cit2->coeff));
                        ++cit2;
                        // copy first changed element
                        s->push_back(combine_ex_with_coeff_to_pair(expanded_ex,
                                                                   cit2->coeff));
                        ++cit2;
+
                        // copy rest
                        while (cit2!=last) {
                                s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.expand(options),
                        // copy rest
                        while (cit2!=last) {
                                s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.expand(options),
@@ -1483,7 +1485,7 @@ epvector * expairseq::expandchildren(unsigned options) const
                ++cit;
        }
        
                ++cit;
        }
        
-       return 0; // signalling nothing has changed
+       return std::auto_ptr<epvector>(0); // signalling nothing has changed
 }
 
 
 }
 
 
@@ -1492,14 +1494,14 @@ epvector * expairseq::expandchildren(unsigned options) const
  *  @see expairseq::eval()
  *  @return pointer to epvector containing evaluated pairs or zero pointer,
  *  if no members were changed. */
  *  @see expairseq::eval()
  *  @return pointer to epvector containing evaluated pairs or zero pointer,
  *  if no members were changed. */
-epvector * expairseq::evalchildren(int level) const
+std::auto_ptr<epvector> expairseq::evalchildren(int level) const
 {
        // returns a NULL pointer if nothing had to be evaluated
        // returns a pointer to a newly created epvector otherwise
        // (which has to be deleted somewhere else)
 
        if (level==1)
 {
        // returns a NULL pointer if nothing had to be evaluated
        // returns a pointer to a newly created epvector otherwise
        // (which has to be deleted somewhere else)
 
        if (level==1)
-               return 0;
+               return std::auto_ptr<epvector>(0);
        
        if (level == -max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
        
        if (level == -max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
@@ -1512,7 +1514,7 @@ epvector * expairseq::evalchildren(int level) const
                if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
                        
                        // something changed, copy seq, eval and return it
                if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
                        
                        // something changed, copy seq, eval and return it
-                       epvector *s = new epvector;
+                       std::auto_ptr<epvector> s(new epvector);
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
@@ -1521,10 +1523,12 @@ epvector * expairseq::evalchildren(int level) const
                                s->push_back(*cit2);
                                ++cit2;
                        }
                                s->push_back(*cit2);
                                ++cit2;
                        }
+
                        // copy first changed element
                        s->push_back(combine_ex_with_coeff_to_pair(evaled_ex,
                                                                   cit2->coeff));
                        ++cit2;
                        // copy first changed element
                        s->push_back(combine_ex_with_coeff_to_pair(evaled_ex,
                                                                   cit2->coeff));
                        ++cit2;
+
                        // copy rest
                        while (cit2!=last) {
                                s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.eval(level),
                        // copy rest
                        while (cit2!=last) {
                                s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.eval(level),
@@ -1536,7 +1540,7 @@ epvector * expairseq::evalchildren(int level) const
                ++cit;
        }
        
                ++cit;
        }
        
-       return 0; // signalling nothing has changed
+       return std::auto_ptr<epvector>(0); // signalling nothing has changed
 }
 
 
 }
 
 
@@ -1545,7 +1549,7 @@ epvector * expairseq::evalchildren(int level) const
  *  @see expairseq::subs()
  *  @return pointer to epvector containing pairs after application of subs,
  *    or NULL pointer if no members were changed. */
  *  @see expairseq::subs()
  *  @return pointer to epvector containing pairs after application of subs,
  *    or NULL pointer if no members were changed. */
-epvector * expairseq::subschildren(const exmap & m, unsigned options) const
+std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned options) const
 {
        // When any of the objects to be substituted is a product or power
        // we have to recombine the pairs because the numeric coefficients may
 {
        // When any of the objects to be substituted is a product or power
        // we have to recombine the pairs because the numeric coefficients may
@@ -1574,7 +1578,7 @@ epvector * expairseq::subschildren(const exmap & m, unsigned options) const
                        if (!are_ex_trivially_equal(orig_ex, subsed_ex)) {
 
                                // Something changed, copy seq, subs and return it
                        if (!are_ex_trivially_equal(orig_ex, subsed_ex)) {
 
                                // Something changed, copy seq, subs and return it
-                               epvector *s = new epvector;
+                               std::auto_ptr<epvector> s(new epvector);
                                s->reserve(seq.size());
 
                                // Copy parts of seq which are known not to have changed
                                s->reserve(seq.size());
 
                                // Copy parts of seq which are known not to have changed
@@ -1605,7 +1609,7 @@ epvector * expairseq::subschildren(const exmap & m, unsigned options) const
                        if (!are_ex_trivially_equal(cit->rest, subsed_ex)) {
                        
                                // Something changed, copy seq, subs and return it
                        if (!are_ex_trivially_equal(cit->rest, subsed_ex)) {
                        
                                // Something changed, copy seq, subs and return it
-                               epvector *s = new epvector;
+                               std::auto_ptr<epvector> s(new epvector);
                                s->reserve(seq.size());
 
                                // Copy parts of seq which are known not to have changed
                                s->reserve(seq.size());
 
                                // Copy parts of seq which are known not to have changed
@@ -1629,7 +1633,7 @@ epvector * expairseq::subschildren(const exmap & m, unsigned options) const
        }
        
        // Nothing has changed
        }
        
        // Nothing has changed
-       return NULL;
+       return std::auto_ptr<epvector>(0);
 }
 
 //////////
 }
 
 //////////
index 6f099b40ac902177470f58558f2feabda19a938c..f789514fe02bdf243f85b24494d2150f2beebefc 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <vector>
 #include <list>
 
 #include <vector>
 #include <list>
+#include <memory>
 // CINT needs <algorithm> to work properly with <vector> and <list>
 #include <algorithm>
 
 // CINT needs <algorithm> to work properly with <vector> and <list>
 #include <algorithm>
 
@@ -66,7 +67,7 @@ public:
        expairseq(const ex & lh, const ex & rh);
        expairseq(const exvector & v);
        expairseq(const epvector & v, const ex & oc);
        expairseq(const ex & lh, const ex & rh);
        expairseq(const exvector & v);
        expairseq(const epvector & v, const ex & oc);
-       expairseq(epvector * vp, const ex & oc); // vp will be deleted
+       expairseq(std::auto_ptr<epvector>, const ex & oc);
        
        // functions overriding virtual functions from base classes
 public:
        
        // functions overriding virtual functions from base classes
 public:
@@ -89,7 +90,7 @@ protected:
        // new virtual functions which can be overridden by derived classes
 protected:
        virtual ex thisexpairseq(const epvector & v, const ex & oc) const;
        // new virtual functions which can be overridden by derived classes
 protected:
        virtual ex thisexpairseq(const epvector & v, const ex & oc) const;
-       virtual ex thisexpairseq(epvector * vp, const ex & oc) const;
+       virtual ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const;
        virtual void printseq(const print_context & c, char delim,
                              unsigned this_precedence,
                              unsigned upper_precedence) const;
        virtual void printseq(const print_context & c, char delim,
                              unsigned this_precedence,
                              unsigned upper_precedence) const;
@@ -145,9 +146,9 @@ protected:
                                     epvector::const_iterator last_non_zero);
 #endif // EXPAIRSEQ_USE_HASHTAB
        bool is_canonical() const;
                                     epvector::const_iterator last_non_zero);
 #endif // EXPAIRSEQ_USE_HASHTAB
        bool is_canonical() const;
-       epvector * expandchildren(unsigned options) const;
-       epvector * evalchildren(int level) const;
-       epvector * subschildren(const exmap & m, unsigned options = 0) const;
+       std::auto_ptr<epvector> expandchildren(unsigned options) const;
+       std::auto_ptr<epvector> evalchildren(int level) const;
+       std::auto_ptr<epvector> subschildren(const exmap & m, unsigned options = 0) const;
        
 // member variables
        
        
 // member variables
        
index d2ebc15c34cf680e012b88bd1c730c112fc3fcb7..e33ec963c4299ec701f53d7e2bc9c4627a598abc 100644 (file)
@@ -57,7 +57,7 @@ fderivative::fderivative(unsigned ser, const paramset & params, const exvector &
        tinfo_key = TINFO_fderivative;
 }
 
        tinfo_key = TINFO_fderivative;
 }
 
-fderivative::fderivative(unsigned ser, const paramset & params, exvector * vp) : function(ser, vp), parameter_set(params)
+fderivative::fderivative(unsigned ser, const paramset & params, std::auto_ptr<exvector> vp) : function(ser, vp), parameter_set(params)
 {
        tinfo_key = TINFO_fderivative;
 }
 {
        tinfo_key = TINFO_fderivative;
 }
@@ -160,7 +160,7 @@ ex fderivative::thiscontainer(const exvector & v) const
        return fderivative(serial, parameter_set, v);
 }
 
        return fderivative(serial, parameter_set, v);
 }
 
-ex fderivative::thiscontainer(exvector * vp) const
+ex fderivative::thiscontainer(std::auto_ptr<exvector> vp) const
 {
        return fderivative(serial, parameter_set, vp);
 }
 {
        return fderivative(serial, parameter_set, vp);
 }
index c165d314135d131693cc0196d9777c45e7d32022..ee3405db0cea5282f801340d1dac0b35cc5055cc 100644 (file)
@@ -56,7 +56,7 @@ public:
        fderivative(unsigned ser, const paramset & params, const exvector & args);
 
        // internal constructors
        fderivative(unsigned ser, const paramset & params, const exvector & args);
 
        // internal constructors
-       fderivative(unsigned ser, const paramset & params, exvector * vp); // vp will be deleted
+       fderivative(unsigned ser, const paramset & params, std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
@@ -64,7 +64,7 @@ public:
        ex evalf(int level = 0) const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex thiscontainer(const exvector & v) const;
        ex evalf(int level = 0) const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
index 7e5d0dac0307ca6db6dbe4427a0461bc9bfb5871..1f944f1a4f9c74a07dc13bb815c34f1dec61a65f 100755 (executable)
@@ -357,7 +357,7 @@ $constructors_interface
        // end of generated lines
        function(unsigned ser, const exprseq & es);
        function(unsigned ser, const exvector & v, bool discardable = false);
        // end of generated lines
        function(unsigned ser, const exprseq & es);
        function(unsigned ser, const exvector & v, bool discardable = false);
-       function(unsigned ser, exvector * vp); // vp will be deleted
+       function(unsigned ser, std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
@@ -369,7 +369,7 @@ public:
        unsigned calchash() const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex thiscontainer(const exvector & v) const;
        unsigned calchash() const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
@@ -661,7 +661,7 @@ function::function(unsigned ser, const exvector & v, bool discardable)
        tinfo_key = TINFO_function;
 }
 
        tinfo_key = TINFO_function;
 }
 
-function::function(unsigned ser, exvector * vp) 
+function::function(unsigned ser, std::auto_ptr<exvector> vp) 
   : exprseq(vp), serial(ser)
 {
        tinfo_key = TINFO_function;
   : exprseq(vp), serial(ser)
 {
        tinfo_key = TINFO_function;
@@ -888,12 +888,12 @@ unsigned function::calchash() const
 
 ex function::thiscontainer(const exvector & v) const
 {
 
 ex function::thiscontainer(const exvector & v) const
 {
-       return function(serial,v);
+       return function(serial, v);
 }
 
 }
 
-ex function::thiscontainer(exvector * vp) const
+ex function::thiscontainer(std::auto_ptr<exvector> vp) const
 {
 {
-       return function(serial,vp);
+       return function(serial, vp);
 }
 
 /** Implementation of ex::series for functions.
 }
 
 /** Implementation of ex::series for functions.
index 562ca1d5c6c0bd95dbc0584df003b11cf1b505be..50e3b01b60b83cbd6b77f5d8cfc0175e19c302dc 100644 (file)
@@ -129,7 +129,7 @@ indexed::indexed(const symmetry & symm, const exvector & v, bool discardable) :
        tinfo_key = TINFO_indexed;
 }
 
        tinfo_key = TINFO_indexed;
 }
 
-indexed::indexed(const symmetry & symm, exvector * vp) : inherited(vp), symtree(symm)
+indexed::indexed(const symmetry & symm, std::auto_ptr<exvector> vp) : inherited(vp), symtree(symm)
 {
        tinfo_key = TINFO_indexed;
 }
 {
        tinfo_key = TINFO_indexed;
 }
@@ -316,7 +316,7 @@ ex indexed::thiscontainer(const exvector & v) const
        return indexed(ex_to<symmetry>(symtree), v);
 }
 
        return indexed(ex_to<symmetry>(symtree), v);
 }
 
-ex indexed::thiscontainer(exvector * vp) const
+ex indexed::thiscontainer(std::auto_ptr<exvector> vp) const
 {
        return indexed(ex_to<symmetry>(symtree), vp);
 }
 {
        return indexed(ex_to<symmetry>(symtree), vp);
 }
index d798107f8cf31eb23ac272cfb89e136a3e9ac1f0..30c29e8e167e3fa788ceead1e9c446b596e232a4 100644 (file)
@@ -140,7 +140,7 @@ public:
        // internal constructors
        indexed(const symmetry & symm, const exprseq & es);
        indexed(const symmetry & symm, const exvector & v, bool discardable = false);
        // internal constructors
        indexed(const symmetry & symm, const exprseq & es);
        indexed(const symmetry & symm, const exvector & v, bool discardable = false);
-       indexed(const symmetry & symm, exvector * vp); // vp will be deleted
+       indexed(const symmetry & symm, std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
@@ -152,7 +152,7 @@ public:
 protected:
        ex derivative(const symbol & s) const;
        ex thiscontainer(const exvector & v) const;
 protected:
        ex derivative(const symbol & s) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::commutative; }
        ex expand(unsigned options = 0) const;
 
        unsigned return_type() const { return return_types::commutative; }
        ex expand(unsigned options = 0) const;
 
index f2834131b0c914fe5546d76c7f8da862cd038864..6f99c515062ff86c64a253ae9ce80adf512680bb 100644 (file)
@@ -91,13 +91,12 @@ mul::mul(const epvector & v, const ex & oc)
        GINAC_ASSERT(is_canonical());
 }
 
        GINAC_ASSERT(is_canonical());
 }
 
-mul::mul(epvector * vp, const ex & oc)
+mul::mul(std::auto_ptr<epvector> vp, const ex & oc)
 {
        tinfo_key = TINFO_mul;
        GINAC_ASSERT(vp!=0);
        overall_coeff = oc;
        construct_from_epvector(*vp);
 {
        tinfo_key = TINFO_mul;
        GINAC_ASSERT(vp!=0);
        overall_coeff = oc;
        construct_from_epvector(*vp);
-       delete vp;
        GINAC_ASSERT(is_canonical());
 }
 
        GINAC_ASSERT(is_canonical());
 }
 
@@ -379,10 +378,10 @@ ex mul::coeff(const ex & s, int n) const
  *  @param level cut-off in recursive evaluation */
 ex mul::eval(int level) const
 {
  *  @param level cut-off in recursive evaluation */
 ex mul::eval(int level) const
 {
-       epvector *evaled_seqp = evalchildren(level);
-       if (evaled_seqp) {
+       std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
+       if (evaled_seqp.get()) {
                // do more evaluation later
                // do more evaluation later
-               return (new mul(evaled_seqp,overall_coeff))->
+               return (new mul(evaled_seqp, overall_coeff))->
                           setflag(status_flags::dynallocated);
        }
        
                           setflag(status_flags::dynallocated);
        }
        
@@ -425,7 +424,7 @@ ex mul::eval(int level) const
                   ex_to<numeric>((*seq.begin()).coeff).is_equal(_num1)) {
                // *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
                const add & addref = ex_to<add>((*seq.begin()).rest);
                   ex_to<numeric>((*seq.begin()).coeff).is_equal(_num1)) {
                // *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
                const add & addref = ex_to<add>((*seq.begin()).rest);
-               epvector *distrseq = new epvector();
+               std::auto_ptr<epvector> distrseq(new epvector);
                distrseq->reserve(addref.seq.size());
                epvector::const_iterator i = addref.seq.begin(), end = addref.seq.end();
                while (i != end) {
                distrseq->reserve(addref.seq.size());
                epvector::const_iterator i = addref.seq.begin(), end = addref.seq.end();
                while (i != end) {
@@ -448,7 +447,7 @@ ex mul::evalf(int level) const
        if (level==-max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
        
        if (level==-max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
        
-       epvector *s = new epvector();
+       std::auto_ptr<epvector> s(new epvector);
        s->reserve(seq.size());
 
        --level;
        s->reserve(seq.size());
 
        --level;
@@ -471,7 +470,7 @@ ex mul::evalm() const
        // Evaluate children first, look whether there are any matrices at all
        // (there can be either no matrices or one matrix; if there were more
        // than one matrix, it would be a non-commutative product)
        // Evaluate children first, look whether there are any matrices at all
        // (there can be either no matrices or one matrix; if there were more
        // than one matrix, it would be a non-commutative product)
-       epvector *s = new epvector;
+       std::auto_ptr<epvector> s(new epvector);
        s->reserve(seq.size());
 
        bool have_matrix = false;
        s->reserve(seq.size());
 
        bool have_matrix = false;
@@ -724,7 +723,7 @@ ex mul::thisexpairseq(const epvector & v, const ex & oc) const
        return (new mul(v, oc))->setflag(status_flags::dynallocated);
 }
 
        return (new mul(v, oc))->setflag(status_flags::dynallocated);
 }
 
-ex mul::thisexpairseq(epvector * vp, const ex & oc) const
+ex mul::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const
 {
        return (new mul(vp, oc))->setflag(status_flags::dynallocated);
 }
 {
        return (new mul(vp, oc))->setflag(status_flags::dynallocated);
 }
@@ -828,8 +827,8 @@ bool mul::can_make_flat(const expair & p) const
 ex mul::expand(unsigned options) const
 {
        // First, expand the children
 ex mul::expand(unsigned options) const
 {
        // First, expand the children
-       epvector * expanded_seqp = expandchildren(options);
-       const epvector & expanded_seq = (expanded_seqp == NULL) ? seq : *expanded_seqp;
+       std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
+       const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
 
        // Now, look for all the factors that are sums and multiply each one out
        // with the next one that is found while collecting the factors which are
 
        // Now, look for all the factors that are sums and multiply each one out
        // with the next one that is found while collecting the factors which are
@@ -906,8 +905,6 @@ ex mul::expand(unsigned options) const
                }
                ++cit;
        }
                }
                ++cit;
        }
-       if (expanded_seqp)
-               delete expanded_seqp;
        
        // Now the only remaining thing to do is to multiply the factors which
        // were not sums into the "last_expanded" sum
        
        // Now the only remaining thing to do is to multiply the factors which
        // were not sums into the "last_expanded" sum
@@ -949,7 +946,7 @@ ex mul::expand(unsigned options) const
  *  @see mul::expand()
  *  @return pointer to epvector containing expanded representation or zero
  *  pointer, if sequence is unchanged. */
  *  @see mul::expand()
  *  @return pointer to epvector containing expanded representation or zero
  *  pointer, if sequence is unchanged. */
-epvector * mul::expandchildren(unsigned options) const
+std::auto_ptr<epvector> mul::expandchildren(unsigned options) const
 {
        const epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
 {
        const epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
@@ -959,7 +956,7 @@ epvector * mul::expandchildren(unsigned options) const
                if (!are_ex_trivially_equal(factor,expanded_factor)) {
                        
                        // something changed, copy seq, eval and return it
                if (!are_ex_trivially_equal(factor,expanded_factor)) {
                        
                        // something changed, copy seq, eval and return it
-                       epvector *s = new epvector;
+                       std::auto_ptr<epvector> s(new epvector);
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
@@ -968,9 +965,11 @@ epvector * mul::expandchildren(unsigned options) const
                                s->push_back(*cit2);
                                ++cit2;
                        }
                                s->push_back(*cit2);
                                ++cit2;
                        }
+
                        // copy first changed element
                        s->push_back(split_ex_to_pair(expanded_factor));
                        ++cit2;
                        // copy first changed element
                        s->push_back(split_ex_to_pair(expanded_factor));
                        ++cit2;
+
                        // copy rest
                        while (cit2!=last) {
                                s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit2).expand(options)));
                        // copy rest
                        while (cit2!=last) {
                                s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit2).expand(options)));
@@ -981,7 +980,7 @@ epvector * mul::expandchildren(unsigned options) const
                ++cit;
        }
        
                ++cit;
        }
        
-       return 0; // nothing has changed
+       return std::auto_ptr<epvector>(0); // nothing has changed
 }
 
 } // namespace GiNaC
 }
 
 } // namespace GiNaC
index e6aa161654871049301fb6f3e4c0484b1045b560..25c48f4f71beb6de3e08f0b41707afe5f7827725 100644 (file)
@@ -42,7 +42,7 @@ public:
        mul(const exvector & v);
        mul(const epvector & v);
        mul(const epvector & v, const ex & oc);
        mul(const exvector & v);
        mul(const epvector & v);
        mul(const epvector & v, const ex & oc);
-       mul(epvector * vp, const ex & oc);
+       mul(std::auto_ptr<epvector> vp, const ex & oc);
        mul(const ex & lh, const ex & mh, const ex & rh);
        
        // functions overriding virtual functions from base classes
        mul(const ex & lh, const ex & mh, const ex & rh);
        
        // functions overriding virtual functions from base classes
@@ -67,7 +67,7 @@ protected:
        unsigned return_type() const;
        unsigned return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc) const;
        unsigned return_type() const;
        unsigned return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc) const;
-       ex thisexpairseq(epvector * vp, const ex & oc) const;
+       ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const;
        expair split_ex_to_pair(const ex & e) const;
        expair combine_ex_with_coeff_to_pair(const ex & e, const ex & c) const;
        expair combine_pair_with_coeff_to_pair(const expair & p, const ex & c) const;
        expair split_ex_to_pair(const ex & e) const;
        expair combine_ex_with_coeff_to_pair(const ex & e, const ex & c) const;
        expair combine_pair_with_coeff_to_pair(const expair & p, const ex & c) const;
@@ -91,7 +91,7 @@ protected:
        void do_print_latex(const print_latex & c, unsigned level) const;
        void do_print_csrc(const print_csrc & c, unsigned level) const;
        void do_print_python_repr(const print_python_repr & c, unsigned level) const;
        void do_print_latex(const print_latex & c, unsigned level) const;
        void do_print_csrc(const print_csrc & c, unsigned level) const;
        void do_print_python_repr(const print_python_repr & c, unsigned level) const;
-       epvector * expandchildren(unsigned options) const;
+       std::auto_ptr<epvector> expandchildren(unsigned options) const;
 };
 
 // utility functions
 };
 
 // utility functions
index 163c3c864ef250da663fefc647a9c3d7e6831921..e3a6b552f7e6d0294022fb69603083325ec40b4f 100644 (file)
@@ -89,7 +89,7 @@ ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable)
        tinfo_key = TINFO_ncmul;
 }
 
        tinfo_key = TINFO_ncmul;
 }
 
-ncmul::ncmul(exvector * vp) : inherited(vp)
+ncmul::ncmul(std::auto_ptr<exvector> vp) : inherited(vp)
 {
        tinfo_key = TINFO_ncmul;
 }
 {
        tinfo_key = TINFO_ncmul;
 }
@@ -420,7 +420,7 @@ ex ncmul::eval(int level) const
 ex ncmul::evalm() const
 {
        // Evaluate children first
 ex ncmul::evalm() const
 {
        // Evaluate children first
-       exvector *s = new exvector;
+       std::auto_ptr<exvector> s(new exvector);
        s->reserve(seq.size());
        exvector::const_iterator it = seq.begin(), itend = seq.end();
        while (it != itend) {
        s->reserve(seq.size());
        exvector::const_iterator it = seq.begin(), itend = seq.end();
        while (it != itend) {
@@ -439,7 +439,6 @@ ex ncmul::evalm() const
                        prod = prod.mul(ex_to<matrix>(*it));
                        it++;
                }
                        prod = prod.mul(ex_to<matrix>(*it));
                        it++;
                }
-               delete s;
                return prod;
        }
 
                return prod;
        }
 
@@ -452,7 +451,7 @@ ex ncmul::thiscontainer(const exvector & v) const
        return (new ncmul(v))->setflag(status_flags::dynallocated);
 }
 
        return (new ncmul(v))->setflag(status_flags::dynallocated);
 }
 
-ex ncmul::thiscontainer(exvector * vp) const
+ex ncmul::thiscontainer(std::auto_ptr<exvector> vp) const
 {
        return (new ncmul(vp))->setflag(status_flags::dynallocated);
 }
 {
        return (new ncmul(vp))->setflag(status_flags::dynallocated);
 }
index 57cb08c7e37c8268a835f3ebab5bd0e912610060..0139a63fe74dce0f8be73f16763bf52d3e110213 100644 (file)
@@ -49,7 +49,7 @@ public:
        ncmul(const ex & f1, const ex & f2, const ex & f3,
              const ex & f4, const ex & f5, const ex & f6);
        ncmul(const exvector & v, bool discardable=false);
        ncmul(const ex & f1, const ex & f2, const ex & f3,
              const ex & f4, const ex & f5, const ex & f6);
        ncmul(const exvector & v, bool discardable=false);
-       ncmul(exvector * vp); // vp will be deleted
+       ncmul(std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 public:
 
        // functions overriding virtual functions from base classes
 public:
@@ -63,7 +63,7 @@ public:
        ex evalm() const;
        exvector get_free_indices() const;
        ex thiscontainer(const exvector & v) const;
        ex evalm() const;
        exvector get_free_indices() const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
 
 protected:
        ex derivative(const symbol & s) const;
 
 protected:
        ex derivative(const symbol & s) const;