Remove dependence on depreacted std::auto_ptr<T>.
authorRichard Kreckel <kreckel@ginac.de>
Sun, 1 Nov 2015 19:16:12 +0000 (20:16 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 1 Nov 2015 22:37:31 +0000 (23:37 +0100)
Most of the auto_ptr were introduced to avoid copying. C++11 supports
move semantics for this. Some other can be replaced by std::unique_ptr<T>.

22 files changed:
ginac/add.cpp
ginac/add.h
ginac/clifford.cpp
ginac/clifford.h
ginac/color.cpp
ginac/color.h
ginac/container.h
ginac/ex.h
ginac/expairseq.cpp
ginac/expairseq.h
ginac/fderivative.cpp
ginac/fderivative.h
ginac/function.cppy
ginac/function.hppy
ginac/indexed.cpp
ginac/indexed.h
ginac/mul.cpp
ginac/mul.h
ginac/ncmul.cpp
ginac/ncmul.h
ginac/normal.cpp
ginac/print.h

index 9110491..36bb201 100644 (file)
@@ -86,11 +86,10 @@ add::add(const epvector & v, const ex & oc)
        GINAC_ASSERT(is_canonical());
 }
 
-add::add(std::auto_ptr<epvector> vp, const ex & oc)
+add::add(epvector && vp, const ex & oc)
 {
-       GINAC_ASSERT(vp.get()!=0);
        overall_coeff = oc;
-       construct_from_epvector(*vp);
+       construct_from_epvector(std::move(vp));
        GINAC_ASSERT(is_canonical());
 }
 
@@ -306,8 +305,8 @@ int add::ldegree(const ex & s) const
 
 ex add::coeff(const ex & s, int n) const
 {
-       std::auto_ptr<epvector> coeffseq(new epvector);
-       std::auto_ptr<epvector> coeffseq_cliff(new epvector);
+       epvector coeffseq;
+       epvector coeffseq_cliff;
        int rl = clifford_max_label(s);
        bool do_clifford = (rl != -1);
        bool nonscalar = false;
@@ -319,18 +318,18 @@ ex add::coeff(const ex & s, int n) const
                if (!restcoeff.is_zero()) {
                        if (do_clifford) {
                                if (clifford_max_label(restcoeff) == -1) {
-                                       coeffseq_cliff->push_back(combine_ex_with_coeff_to_pair(ncmul(restcoeff, dirac_ONE(rl)), i->coeff));
+                                       coeffseq_cliff.push_back(combine_ex_with_coeff_to_pair(ncmul(restcoeff, dirac_ONE(rl)), i->coeff));
                                } else {
-                                       coeffseq_cliff->push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
+                                       coeffseq_cliff.push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
                                        nonscalar = true;
                                }
                        }
-                       coeffseq->push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
+                       coeffseq.push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
                }
                ++i;
        }
 
-       return (new add(nonscalar ? coeffseq_cliff : coeffseq,
+       return (new add(nonscalar ? std::move(coeffseq_cliff) : std::move(coeffseq),
                        n==0 ? overall_coeff : _ex0))->setflag(status_flags::dynallocated);
 }
 
@@ -343,13 +342,13 @@ ex add::coeff(const ex & s, int n) const
  *  @param level cut-off in recursive evaluation */
 ex add::eval(int level) const
 {
-       std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
-       if (evaled_seqp.get()) {
+       epvector evaled = evalchildren(level);
+       if (!evaled.empty()) {
                // do more evaluation later
-               return (new add(evaled_seqp, overall_coeff))->
-                      setflag(status_flags::dynallocated);
+               return (new add(std::move(evaled), overall_coeff))->
+                       setflag(status_flags::dynallocated);
        }
-       
+
 #ifdef DO_GINAC_ASSERT
        epvector::const_iterator i = seq.begin(), end = seq.end();
        while (i != end) {
@@ -386,18 +385,18 @@ ex add::eval(int level) const
                ++j;
        }
        if (terms_to_collect) {
-               std::auto_ptr<epvector> s(new epvector);
-               s->reserve(seq_size - terms_to_collect);
+               epvector s;
+               s.reserve(seq_size - terms_to_collect);
                numeric oc = *_num1_p;
                j = seq.begin();
                while (j != last) {
                        if (unlikely(is_a<numeric>(j->rest)))
                                oc = oc.mul(ex_to<numeric>(j->rest)).mul(ex_to<numeric>(j->coeff));
                        else
-                               s->push_back(*j);
+                               s.push_back(*j);
                        ++j;
                }
-               return (new add(s, ex_to<numeric>(overall_coeff).add_dyn(oc)))
+               return (new add(std::move(s), ex_to<numeric>(overall_coeff).add_dyn(oc)))
                        ->setflag(status_flags::dynallocated);
        }
        
@@ -408,8 +407,8 @@ ex add::evalm() const
 {
        // Evaluate children first and add up all matrices. Stop if there's one
        // term that is not a matrix.
-       std::auto_ptr<epvector> s(new epvector);
-       s->reserve(seq.size());
+       epvector s;
+       s.reserve(seq.size());
 
        bool all_matrices = true;
        bool first_term = true;
@@ -418,7 +417,7 @@ ex add::evalm() const
        epvector::const_iterator it = seq.begin(), itend = seq.end();
        while (it != itend) {
                const ex &m = recombine_pair_to_ex(*it).evalm();
-               s->push_back(split_ex_to_pair(m));
+               s.push_back(split_ex_to_pair(m));
                if (is_a<matrix>(m)) {
                        if (first_term) {
                                sum = ex_to<matrix>(m);
@@ -433,7 +432,7 @@ ex add::evalm() const
        if (all_matrices)
                return sum + overall_coeff;
        else
-               return (new add(s, overall_coeff))->setflag(status_flags::dynallocated);
+               return (new add(std::move(s), overall_coeff))->setflag(status_flags::dynallocated);
 }
 
 ex add::conjugate() const
@@ -512,18 +511,18 @@ ex add::eval_ncmul(const exvector & v) const
  *  @see ex::diff */
 ex add::derivative(const symbol & y) const
 {
-       std::auto_ptr<epvector> s(new epvector);
-       s->reserve(seq.size());
+       epvector s;
+       s.reserve(seq.size());
        
        // Only differentiate the "rest" parts of the expairs. This is faster
        // than the default implementation in basic::derivative() although
        // if performs the same function (differentiate each term).
        epvector::const_iterator i = seq.begin(), end = seq.end();
        while (i != end) {
-               s->push_back(combine_ex_with_coeff_to_pair(i->rest.diff(y), i->coeff));
+               s.push_back(combine_ex_with_coeff_to_pair(i->rest.diff(y), i->coeff));
                ++i;
        }
-       return (new add(s, _ex0))->setflag(status_flags::dynallocated);
+       return (new add(std::move(s), _ex0))->setflag(status_flags::dynallocated);
 }
 
 int add::compare_same_type(const basic & other) const
@@ -554,9 +553,9 @@ ex add::thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming)
 }
 
 // Note: do_index_renaming is ignored because it makes no sense for an add.
-ex add::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming) const
+ex add::thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming) const
 {
-       return (new add(vp,oc))->setflag(status_flags::dynallocated);
+       return (new add(std::move(vp), oc))->setflag(status_flags::dynallocated);
 }
 
 expair add::split_ex_to_pair(const ex & e) const
@@ -624,13 +623,12 @@ ex add::recombine_pair_to_ex(const expair & p) const
 
 ex add::expand(unsigned options) const
 {
-       std::auto_ptr<epvector> vp = expandchildren(options);
-       if (vp.get() == 0) {
-               // the terms have not changed, so it is safe to declare this expanded
+       epvector expanded = expandchildren(options);
+       if (expanded.empty())
                return (options == 0) ? setflag(status_flags::expanded) : *this;
-       }
 
-       return (new add(vp, overall_coeff))->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
+       return (new add(std::move(expanded), overall_coeff))->setflag(status_flags::dynallocated |
+                                                                     (options == 0 ? status_flags::expanded : 0));
 }
 
 } // namespace GiNaC
index 3127eaf..db9bda9 100644 (file)
@@ -41,7 +41,7 @@ public:
        add(const exvector & v);
        add(const epvector & v);
        add(const epvector & v, const ex & oc);
-       add(std::auto_ptr<epvector> vp, const ex & oc);
+       add(epvector && vp, const ex & oc);
        
        // functions overriding virtual functions from base classes
 public:
@@ -68,7 +68,7 @@ protected:
        unsigned return_type() const;
        return_type_t return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
-       ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
+       ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) 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 1e93767..eb94e0b 100644 (file)
@@ -109,7 +109,7 @@ clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, const exvec
 {
 }
 
-clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr), commutator_sign(comm_sign)
+clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, exvector && v) : inherited(not_symmetric(), std::move(v)), representation_label(rl), metric(metr), commutator_sign(comm_sign)
 {
 }
 
@@ -685,9 +685,9 @@ ex clifford::thiscontainer(const exvector & v) const
        return clifford(representation_label, metric, commutator_sign, v);
 }
 
-ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
+ex clifford::thiscontainer(exvector && v) const
 {
-       return clifford(representation_label, metric, commutator_sign, vp);
+       return clifford(representation_label, metric, commutator_sign, std::move(v));
 }
 
 ex diracgamma5::conjugate() const
index ea34a9b..bb3a7fe 100644 (file)
@@ -47,7 +47,7 @@ public:
 
        // internal constructors
        clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable = false);
-       clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr<exvector> vp);
+       clifford(unsigned char rl, const ex & metr, int comm_sign, exvector && v);
 
        // functions overriding virtual functions from base classes
 public:
@@ -58,7 +58,7 @@ protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex thiscontainer(exvector && v) const;
        unsigned return_type() const { return return_types::noncommutative; }
        return_type_t return_type_tinfo() const;
        // non-virtual functions in this class
index 9a0d353..09e5251 100644 (file)
@@ -90,7 +90,7 @@ color::color(unsigned char rl, const exvector & v, bool discardable) : inherited
 {
 }
 
-color::color(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl)
+color::color(unsigned char rl, exvector && v) : inherited(not_symmetric(), std::move(v)), representation_label(rl)
 {
 }
 
@@ -184,9 +184,9 @@ ex color::thiscontainer(const exvector & v) const
        return color(representation_label, v);
 }
 
-ex color::thiscontainer(std::auto_ptr<exvector> vp) const
+ex color::thiscontainer(exvector && v) const
 {
-       return color(representation_label, vp);
+       return color(representation_label, std::move(v));
 }
 
 /** Given a vector iv3 of three indices and a vector iv2 of two indices that
index 26eed02..e4a11e4 100644 (file)
@@ -47,7 +47,7 @@ public:
 
        // internal constructors
        color(unsigned char rl, const exvector & v, bool discardable = false);
-       color(unsigned char rl, std::auto_ptr<exvector> vp);
+       color(unsigned char rl, exvector && v);
        void archive(archive_node& n) const;
        void read_archive(const archive_node& n, lst& sym_lst);
 
@@ -56,7 +56,7 @@ protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex thiscontainer(exvector && v) const;
        unsigned return_type() const { return return_types::noncommutative; }
        return_type_t return_type_tinfo() const;
 
index 0c36f7c..6cdc7cb 100644 (file)
@@ -152,10 +152,10 @@ public:
                        this->seq = s;
        }
 
-       explicit container(std::auto_ptr<STLT> vp)
+       explicit container(STLT && v)
        {
                setflag(get_default_flags());
-               this->seq.swap(*vp);
+               this->seq.swap(v);
        }
 
        container(exvector::const_iterator b, exvector::const_iterator e)
@@ -450,8 +450,8 @@ protected:
        virtual ex thiscontainer(const STLT & v) const { return container(v); }
 
        /** Similar to duplicate(), but with a preset sequence (which gets
-        *  deleted). Must be overridden by derived classes. */
-       virtual ex thiscontainer(std::auto_ptr<STLT> vp) const { return container(vp); }
+        *  pilfered). Must be overridden by derived classes. */
+       virtual ex thiscontainer(STLT && v) const { return container(std::move(v)); }
 
        virtual void printseq(const print_context & c, char openbracket, char delim,
                              char closebracket, unsigned this_precedence,
@@ -495,7 +495,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;
-       std::auto_ptr<STLT> subschildren(const exmap & m, unsigned options = 0) const;
+       STLT subschildren(const exmap & m, unsigned options = 0) const;
 };
 
 /** Default constructor */
@@ -582,9 +582,9 @@ ex container<C>::subs(const exmap & m, unsigned options) const
        // f(x).subs(x==f^-1(x))
        //   -> f(f^-1(x))  [subschildren]
        //   -> x           [eval]   /* must not subs(x==f^-1(x))! */
-       std::auto_ptr<STLT> vp = subschildren(m, options);
-       if (vp.get()) {
-               ex result(thiscontainer(vp));
+       STLT subsed = subschildren(m, options);
+       if (!subsed.empty()) {
+               ex result(thiscontainer(subsed));
                if (is_a<container<C> >(result))
                        return ex_to<basic>(result).subs_one_level(m, options);
                else
@@ -751,11 +751,10 @@ typename container<C>::STLT container<C>::evalchildren(int level) const
 }
 
 template <template <class T, class = std::allocator<T> > class C>
-std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exmap & m, unsigned options) const
+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 STLT otherwise
-       // (and relinquishes responsibility for the STLT)
+       // returns an empty container if nothing had to be substituted
+       // returns a STLT with substituted elements otherwise
 
        const_iterator cit = this->seq.begin(), end = this->seq.end();
        while (cit != end) {
@@ -763,16 +762,16 @@ std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exma
                if (!are_ex_trivially_equal(*cit, subsed_ex)) {
 
                        // copy first part of seq which hasn't changed
-                       std::auto_ptr<STLT> s(new STLT(this->seq.begin(), cit));
-                       this->reserve(*s, this->seq.size());
+                       STLT s(this->seq.begin(), cit);
+                       this->reserve(s, this->seq.size());
 
                        // insert changed element
-                       s->push_back(subsed_ex);
+                       s.push_back(subsed_ex);
                        ++cit;
 
                        // copy rest
                        while (cit != end) {
-                               s->push_back(cit->subs(m, options));
+                               s.push_back(cit->subs(m, options));
                                ++cit;
                        }
 
@@ -782,7 +781,7 @@ std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exma
                ++cit;
        }
        
-       return std::auto_ptr<STLT>(0); // nothing has changed
+       return STLT(); // nothing has changed
 }
 
 } // namespace GiNaC
index de0fbff..0bf63a0 100644 (file)
@@ -373,9 +373,9 @@ public:
 
        // This should return an ex*, but that would be a pointer to a
        // temporary value
-       std::auto_ptr<ex> operator->() const
+       std::unique_ptr<ex> operator->() const
        {
-               return std::auto_ptr<ex>(new ex(operator*()));
+               return std::unique_ptr<ex>(new ex(operator*()));
        }
 
        ex operator[](difference_type n) const
index 18aba0d..963cd23 100644 (file)
@@ -95,12 +95,11 @@ expairseq::expairseq(const epvector &v, const ex &oc, bool do_index_renaming)
        GINAC_ASSERT(is_canonical());
 }
 
-expairseq::expairseq(std::auto_ptr<epvector> vp, const ex &oc, bool do_index_renaming)
+expairseq::expairseq(epvector && vp, const ex &oc, bool do_index_renaming)
   :  overall_coeff(oc)
 {
-       GINAC_ASSERT(vp.get()!=0);
        GINAC_ASSERT(is_a<numeric>(oc));
-       construct_from_epvector(*vp, do_index_renaming);
+       construct_from_epvector(std::move(vp), do_index_renaming);
        GINAC_ASSERT(is_canonical());
 }
 
@@ -220,24 +219,24 @@ ex expairseq::op(size_t i) const
 
 ex expairseq::map(map_function &f) const
 {
-       std::auto_ptr<epvector> v(new epvector);
-       v->reserve(seq.size()+1);
+       epvector v;
+       v.reserve(seq.size()+1);
 
        epvector::const_iterator cit = seq.begin(), last = seq.end();
        while (cit != last) {
-               v->push_back(split_ex_to_pair(f(recombine_pair_to_ex(*cit))));
+               v.push_back(split_ex_to_pair(f(recombine_pair_to_ex(*cit))));
                ++cit;
        }
 
        if (overall_coeff.is_equal(default_overall_coeff()))
-               return thisexpairseq(v, default_overall_coeff(), true);
+               return thisexpairseq(std::move(v), default_overall_coeff(), true);
        else {
                ex newcoeff = f(overall_coeff);
                if(is_a<numeric>(newcoeff))
-                       return thisexpairseq(v, newcoeff, true);
+                       return thisexpairseq(std::move(v), newcoeff, true);
                else {
-                       v->push_back(split_ex_to_pair(newcoeff));
-                       return thisexpairseq(v, default_overall_coeff(), true);
+                       v.push_back(split_ex_to_pair(newcoeff));
+                       return thisexpairseq(std::move(v), default_overall_coeff(), true);
                }
        }
 }
@@ -247,12 +246,12 @@ ex expairseq::eval(int level) const
 {
        if ((level==1) && (flags &status_flags::evaluated))
                return *this;
-       
-       std::auto_ptr<epvector> vp = evalchildren(level);
-       if (vp.get() == 0)
+
+       epvector evaled = evalchildren(level);
+       if (!evaled.empty())
+               return (new expairseq(std::move(evaled), overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
+       else
                return this->hold();
-       
-       return (new expairseq(vp, overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
 }
 
 epvector* conjugateepvector(const epvector&epv)
@@ -281,12 +280,15 @@ ex expairseq::conjugate() const
 {
        epvector* newepv = conjugateepvector(seq);
        ex x = overall_coeff.conjugate();
-       if (!newepv && are_ex_trivially_equal(x, overall_coeff)) {
+       if (newepv) {
+               ex result = thisexpairseq(std::move(*newepv), x);
+               delete newepv;
+               return result;
+       }
+       if (are_ex_trivially_equal(x, overall_coeff)) {
                return *this;
        }
-       ex result = thisexpairseq(newepv ? *newepv : seq, x);
-       delete newepv;
-       return result;
+       return thisexpairseq(seq, x);
 }
 
 bool expairseq::match(const ex & pattern, exmap & repl_lst) const
@@ -347,11 +349,11 @@ found:            ;
                        // it has already been matched before, in which case the matches
                        // must be equal)
                        size_t num = ops.size();
-                       std::auto_ptr<epvector> vp(new epvector);
-                       vp->reserve(num);
+                       epvector vp;
+                       vp.reserve(num);
                        for (size_t i=0; i<num; i++)
-                               vp->push_back(split_ex_to_pair(ops[i]));
-                       ex rest = thisexpairseq(vp, default_overall_coeff());
+                               vp.push_back(split_ex_to_pair(ops[i]));
+                       ex rest = thisexpairseq(std::move(vp), default_overall_coeff());
                        for (exmap::const_iterator it = tmp_repl.begin(); it != tmp_repl.end(); ++it) {
                                if (it->first.is_equal(global_wildcard)) {
                                        if (rest.is_equal(it->second)) {
@@ -381,9 +383,9 @@ found:              ;
 
 ex expairseq::subs(const exmap & m, unsigned options) const
 {
-       std::auto_ptr<epvector> vp = subschildren(m, options);
-       if (vp.get())
-               return ex_to<basic>(thisexpairseq(vp, overall_coeff, (options & subs_options::no_index_renaming) == 0));
+       epvector subsed = subschildren(m, options);
+       if (!subsed.empty())
+               return ex_to<basic>(thisexpairseq(std::move(subsed), overall_coeff, (options & subs_options::no_index_renaming) == 0));
        else if ((options & subs_options::algebraic) && is_exactly_a<mul>(*this))
                return static_cast<const mul *>(this)->algebraic_subs_mul(m, options);
        else
@@ -461,7 +463,6 @@ unsigned expairseq::calchash() const
        const epvector::const_iterator end = seq.end();
        while (i != end) {
                v ^= i->rest.gethash();
-               // rotation spoils commutativity!
                v = rotate_left(v);
                v ^= i->coeff.gethash();
                ++i;
@@ -480,13 +481,11 @@ unsigned expairseq::calchash() const
 
 ex expairseq::expand(unsigned options) const
 {
-       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;
+       epvector expanded = expandchildren(options);
+       if (!expanded.empty()) {
+               return thisexpairseq(std::move(expanded), overall_coeff);
        }
+       return (options == 0) ? setflag(status_flags::expanded) : *this;
 }
 
 //////////
@@ -508,9 +507,9 @@ ex expairseq::thisexpairseq(const epvector &v, const ex &oc, bool do_index_renam
        return expairseq(v, oc, do_index_renaming);
 }
 
-ex expairseq::thisexpairseq(std::auto_ptr<epvector> vp, const ex &oc, bool do_index_renaming) const
+ex expairseq::thisexpairseq(epvector && vp, const ex &oc, bool do_index_renaming) const
 {
-       return expairseq(vp, oc, do_index_renaming);
+       return expairseq(std::move(vp), oc, do_index_renaming);
 }
 
 void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const
@@ -735,7 +734,7 @@ void expairseq::construct_from_2_expairseq(const expairseq &s1,
        if (needs_further_processing) {
                epvector v = seq;
                seq.clear();
-               construct_from_epvector(v);
+               construct_from_epvector(std::move(v));
        }
 }
 
@@ -797,7 +796,7 @@ void expairseq::construct_from_expairseq_ex(const expairseq &s,
        if (needs_further_processing) {
                epvector v = seq;
                seq.clear();
-               construct_from_epvector(v);
+               construct_from_epvector(std::move(v));
        }
 }
 
@@ -825,6 +824,18 @@ void expairseq::construct_from_epvector(const epvector &v, bool do_index_renamin
        combine_same_terms_sorted_seq();
 }
 
+void expairseq::construct_from_epvector(epvector &&v, bool do_index_renaming)
+{
+       // simplifications: +(a,+(b,c),d) -> +(a,b,c,d) (associativity)
+       //                  +(d,b,c,a) -> +(a,b,c,d) (canonicalization)
+       //                  +(...,x,*(x,c1),*(x,c2)) -> +(...,*(x,1+c1+c2)) (c1, c2 numeric)
+       //                  same for (+,*) -> (*,^)
+
+       make_flat(std::move(v), do_index_renaming);
+       canonicalize();
+       combine_same_terms_sorted_seq();
+}
+
 /** Combine this expairseq with argument exvector.
  *  It cares for associativity as well as for special handling of numerics. */
 void expairseq::make_flat(const exvector &v)
@@ -914,13 +925,11 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
                        ex newrest = mf.handle_factor(cit->rest, cit->coeff);
                        const expairseq &subseqref = ex_to<expairseq>(newrest);
                        combine_overall_coeff(ex_to<numeric>(subseqref.overall_coeff),
-                                                           ex_to<numeric>(cit->coeff));
+                                             ex_to<numeric>(cit->coeff));
                        epvector::const_iterator cit_s = subseqref.seq.begin();
                        while (cit_s!=subseqref.seq.end()) {
                                seq.push_back(expair(cit_s->rest,
                                                     ex_to<numeric>(cit_s->coeff).mul_dyn(ex_to<numeric>(cit->coeff))));
-                               //seq.push_back(combine_pair_with_coeff_to_pair(*cit_s,
-                               //                                              (*cit).coeff));
                                ++cit_s;
                        }
                } else {
@@ -991,7 +1000,7 @@ void expairseq::combine_same_terms_sorted_seq()
        if (needs_further_processing) {
                epvector v = seq;
                seq.clear();
-               construct_from_epvector(v);
+               construct_from_epvector(std::move(v));
        }
 }
 
@@ -1029,13 +1038,12 @@ bool expairseq::is_canonical() const
        return 1;
 }
 
-
 /** Member-wise expand the expairs in this sequence.
  *
  *  @see expairseq::expand()
- *  @return pointer to epvector containing expanded pairs or zero pointer,
- *  if no members were changed. */
-std::auto_ptr<epvector> expairseq::expandchildren(unsigned options) const
+ *  @return epvector containing expanded pairs, empty if no members
+ *    had to be changed. */
+epvector expairseq::expandchildren(unsigned options) const
 {
        const epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
@@ -1044,25 +1052,25 @@ std::auto_ptr<epvector> expairseq::expandchildren(unsigned options) const
                if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
                        
                        // something changed, copy seq, eval and return it
-                       std::auto_ptr<epvector> s(new epvector);
-                       s->reserve(seq.size());
+                       epvector s;
+                       s.reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
                        epvector::const_iterator cit2 = seq.begin();
                        while (cit2!=cit) {
-                               s->push_back(*cit2);
+                               s.push_back(*cit2);
                                ++cit2;
                        }
 
                        // copy first changed element
-                       s->push_back(combine_ex_with_coeff_to_pair(expanded_ex,
-                                                                  cit2->coeff));
+                       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),
-                                                                          cit2->coeff));
+                               s.push_back(combine_ex_with_coeff_to_pair(cit2->rest.expand(options),
+                                                                         cit2->coeff));
                                ++cit2;
                        }
                        return s;
@@ -1070,23 +1078,19 @@ std::auto_ptr<epvector> expairseq::expandchildren(unsigned options) const
                ++cit;
        }
        
-       return std::auto_ptr<epvector>(0); // signalling nothing has changed
+       return epvector(); // empty signalling nothing has changed
 }
 
 
 /** Member-wise evaluate the expairs in this sequence.
  *
  *  @see expairseq::eval()
- *  @return pointer to epvector containing evaluated pairs or zero pointer,
- *  if no members were changed. */
-std::auto_ptr<epvector> expairseq::evalchildren(int level) const
+ *  @return epvector containing evaluated pairs, empty if no members
+ *    had to be changed. */
+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)
-               return std::auto_ptr<epvector>(0);
+               return epvector();  // nothing had to be evaluated
        
        if (level == -max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
@@ -1095,45 +1099,45 @@ std::auto_ptr<epvector> expairseq::evalchildren(int level) const
        epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
        while (cit!=last) {
-               const ex &evaled_ex = cit->rest.eval(level);
+               const ex evaled_ex = cit->rest.eval(level);
                if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
                        
                        // something changed, copy seq, eval and return it
-                       std::auto_ptr<epvector> s(new epvector);
-                       s->reserve(seq.size());
+                       epvector s;
+                       s.reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
                        epvector::const_iterator cit2=seq.begin();
                        while (cit2!=cit) {
-                               s->push_back(*cit2);
+                               s.push_back(*cit2);
                                ++cit2;
                        }
 
                        // copy first changed element
-                       s->push_back(combine_ex_with_coeff_to_pair(evaled_ex,
-                                                                  cit2->coeff));
+                       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),
-                                                                          cit2->coeff));
+                               s.push_back(combine_ex_with_coeff_to_pair(cit2->rest.eval(level),
+                                                                         cit2->coeff));
                                ++cit2;
                        }
-                       return s;
+                       return std::move(s);
                }
                ++cit;
        }
-       
-       return std::auto_ptr<epvector>(0); // signalling nothing has changed
+
+       return epvector(); // signalling nothing has changed
 }
 
 /** Member-wise substitute in this sequence.
  *
  *  @see expairseq::subs()
- *  @return pointer to epvector containing pairs after application of subs,
- *    or NULL pointer if no members were changed. */
-std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned options) const
+ *  @return epvector containing expanded pairs, empty if no members
+ *    had to be changed. */
+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
@@ -1162,19 +1166,19 @@ std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned option
                        if (!are_ex_trivially_equal(orig_ex, subsed_ex)) {
 
                                // Something changed, copy seq, subs and return it
-                               std::auto_ptr<epvector> s(new epvector);
-                               s->reserve(seq.size());
+                               epvector s;
+                               s.reserve(seq.size());
 
                                // Copy parts of seq which are known not to have changed
-                               s->insert(s->begin(), seq.begin(), cit);
+                               s.insert(s.begin(), seq.begin(), cit);
 
                                // Copy first changed element
-                               s->push_back(split_ex_to_pair(subsed_ex));
+                               s.push_back(split_ex_to_pair(subsed_ex));
                                ++cit;
 
                                // Copy rest
                                while (cit != last) {
-                                       s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(m, options)));
+                                       s.push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(m, options)));
                                        ++cit;
                                }
                                return s;
@@ -1193,19 +1197,19 @@ std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned option
                        if (!are_ex_trivially_equal(cit->rest, subsed_ex)) {
                        
                                // Something changed, copy seq, subs and return it
-                               std::auto_ptr<epvector> s(new epvector);
-                               s->reserve(seq.size());
+                               epvector s;
+                               s.reserve(seq.size());
 
                                // Copy parts of seq which are known not to have changed
-                               s->insert(s->begin(), seq.begin(), cit);
+                               s.insert(s.begin(), seq.begin(), cit);
                        
                                // Copy first changed element
-                               s->push_back(combine_ex_with_coeff_to_pair(subsed_ex, cit->coeff));
+                               s.push_back(combine_ex_with_coeff_to_pair(subsed_ex, cit->coeff));
                                ++cit;
 
                                // Copy rest
                                while (cit != last) {
-                                       s->push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(m, options), cit->coeff));
+                                       s.push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(m, options), cit->coeff));
                                        ++cit;
                                }
                                return s;
@@ -1216,7 +1220,7 @@ std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned option
        }
        
        // Nothing has changed
-       return std::auto_ptr<epvector>(0);
+       return epvector();
 }
 
 //////////
index 6e98bbf..3220318 100644 (file)
@@ -61,7 +61,7 @@ public:
        expairseq(const ex & lh, const ex & rh);
        expairseq(const exvector & v);
        expairseq(const epvector & v, const ex & oc, bool do_index_renaming = false);
-       expairseq(std::auto_ptr<epvector>, const ex & oc, bool do_index_renaming = false);
+       expairseq(epvector && vp, const ex & oc, bool do_index_renaming = false);
        
        // functions overriding virtual functions from base classes
 public:
@@ -88,7 +88,7 @@ protected:
        // new virtual functions which can be overridden by derived classes
 protected:
        virtual ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
-       virtual ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
+       virtual ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) const;
        virtual void printseq(const print_context & c, char delim,
                              unsigned this_precedence,
                              unsigned upper_precedence) const;
@@ -118,14 +118,15 @@ protected:
                                         const ex & e);
        void construct_from_exvector(const exvector & v);
        void construct_from_epvector(const epvector & v, bool do_index_renaming = false);
+       void construct_from_epvector(epvector && v, bool do_index_renaming = false);
        void make_flat(const exvector & v);
        void make_flat(const epvector & v, bool do_index_renaming = false);
        void canonicalize();
        void combine_same_terms_sorted_seq();
        bool is_canonical() 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;
+       epvector expandchildren(unsigned options) const;
+       epvector evalchildren(int level) const;
+       epvector subschildren(const exmap & m, unsigned options = 0) const;
        
 // member variables
        
index 49b33e6..4229d0a 100644 (file)
@@ -55,7 +55,7 @@ fderivative::fderivative(unsigned ser, const paramset & params, const exvector &
 {
 }
 
-fderivative::fderivative(unsigned ser, const paramset & params, std::auto_ptr<exvector> vp) : function(ser, vp), parameter_set(params)
+fderivative::fderivative(unsigned ser, const paramset & params, exvector && v) : function(ser, std::move(v)), parameter_set(params)
 {
 }
 
@@ -176,9 +176,9 @@ ex fderivative::thiscontainer(const exvector & v) const
        return fderivative(serial, parameter_set, v);
 }
 
-ex fderivative::thiscontainer(std::auto_ptr<exvector> vp) const
+ex fderivative::thiscontainer(exvector && v) const
 {
-       return fderivative(serial, parameter_set, vp);
+       return fderivative(serial, parameter_set, std::move(v));
 }
 
 /** Implementation of ex::diff() for derivatives. It applies the chain rule.
index b990a89..09d8644 100644 (file)
@@ -55,7 +55,7 @@ public:
        fderivative(unsigned ser, const paramset & params, const exvector & args);
 
        // internal constructors
-       fderivative(unsigned ser, const paramset & params, std::auto_ptr<exvector> vp);
+       fderivative(unsigned ser, const paramset & params, exvector && v);
 
        // 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 thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex thiscontainer(exvector && v) const;
        void archive(archive_node& n) const;
        void read_archive(const archive_node& n, lst& syms);
 protected:
index dba9f4e..517f456 100644 (file)
@@ -247,8 +247,8 @@ function::function(unsigned ser, const exvector & v, bool discardable)
 {
 }
 
-function::function(unsigned ser, std::auto_ptr<exvector> vp) 
-  : exprseq(vp), serial(ser)
+function::function(unsigned ser, exvector && v)
+  : exprseq(std::move(v)), serial(ser)
 {
 }
 
@@ -485,9 +485,9 @@ ex function::thiscontainer(const exvector & v) const
        return function(serial, v);
 }
 
-ex function::thiscontainer(std::auto_ptr<exvector> vp) const
+ex function::thiscontainer(exvector && v) const
 {
-       return function(serial, vp);
+       return function(serial, std::move(v));
 }
 
 /** Implementation of ex::series for functions.
index 971786d..b84364d 100644 (file)
@@ -223,7 +223,7 @@ public:
        // end of generated lines
        function(unsigned ser, const exprseq & es);
        function(unsigned ser, const exvector & v, bool discardable = false);
-       function(unsigned ser, std::auto_ptr<exvector> vp);
+       function(unsigned ser, exvector && v);
        
        // functions overriding virtual functions from base classes
 public:
@@ -236,7 +236,7 @@ public:
        unsigned calchash() const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex thiscontainer(exvector && v) const;
        ex conjugate() const;
        ex real_part() const;
        ex imag_part() const;
index 873a9ad..f209829 100644 (file)
@@ -121,7 +121,7 @@ indexed::indexed(const symmetry & symm, const exvector & v, bool discardable) :
 {
 }
 
-indexed::indexed(const symmetry & symm, std::auto_ptr<exvector> vp) : inherited(vp), symtree(symm)
+indexed::indexed(const symmetry & symm, exvector && v) : inherited(std::move(v)), symtree(symm)
 {
 }
 
@@ -324,9 +324,9 @@ ex indexed::thiscontainer(const exvector & v) const
        return indexed(ex_to<symmetry>(symtree), v);
 }
 
-ex indexed::thiscontainer(std::auto_ptr<exvector> vp) const
+ex indexed::thiscontainer(exvector && v) const
 {
-       return indexed(ex_to<symmetry>(symtree), vp);
+       return indexed(ex_to<symmetry>(symtree), std::move(v));
 }
 
 unsigned indexed::return_type() const
index 69e0369..f45f743 100644 (file)
@@ -139,7 +139,7 @@ public:
        // internal constructors
        indexed(const symmetry & symm, const exprseq & es);
        indexed(const symmetry & symm, const exvector & v, bool discardable = false);
-       indexed(const symmetry & symm, std::auto_ptr<exvector> vp);
+       indexed(const symmetry & symm, exvector && v);
 
        // functions overriding virtual functions from base classes
 public:
@@ -157,7 +157,7 @@ public:
 protected:
        ex derivative(const symbol & s) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex thiscontainer(exvector && v) const;
        unsigned return_type() const;
        return_type_t return_type_tinfo() const { return op(0).return_type_tinfo(); }
        ex expand(unsigned options = 0) const;
index 2b40487..f91ac25 100644 (file)
@@ -89,11 +89,10 @@ mul::mul(const epvector & v, const ex & oc, bool do_index_renaming)
        GINAC_ASSERT(is_canonical());
 }
 
-mul::mul(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming)
+mul::mul(epvector && vp, const ex & oc, bool do_index_renaming)
 {
-       GINAC_ASSERT(vp.get()!=0);
        overall_coeff = oc;
-       construct_from_epvector(*vp, do_index_renaming);
+       construct_from_epvector(std::move(vp), do_index_renaming);
        GINAC_ASSERT(is_canonical());
 }
 
@@ -496,13 +495,13 @@ ex mul::coeff(const ex & s, int n) const
  *  @param level cut-off in recursive evaluation */
 ex mul::eval(int level) const
 {
-       std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
-       if (evaled_seqp.get()) {
+       epvector evaled = evalchildren(level);
+       if (!evaled.empty()) {
                // do more evaluation later
-               return (new mul(evaled_seqp, overall_coeff))->
-                          setflag(status_flags::dynallocated);
+               return (new mul(std::move(evaled), overall_coeff))->
+                       setflag(status_flags::dynallocated);
        }
-       
+
        if (flags & status_flags::evaluated) {
                GINAC_ASSERT(seq.size()>0);
                GINAC_ASSERT(seq.size()>1 || !overall_coeff.is_equal(_ex1));
@@ -524,14 +523,14 @@ ex mul::eval(int level) const
                   ex_to<numeric>((*seq.begin()).coeff).is_equal(*_num1_p)) {
                // *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
                const add & addref = ex_to<add>((*seq.begin()).rest);
-               std::auto_ptr<epvector> distrseq(new epvector);
-               distrseq->reserve(addref.seq.size());
+               epvector distrseq;
+               distrseq.reserve(addref.seq.size());
                epvector::const_iterator i = addref.seq.begin(), end = addref.seq.end();
                while (i != end) {
-                       distrseq->push_back(addref.combine_pair_with_coeff_to_pair(*i, overall_coeff));
+                       distrseq.push_back(addref.combine_pair_with_coeff_to_pair(*i, overall_coeff));
                        ++i;
                }
-               return (new add(distrseq,
+               return (new add(std::move(distrseq),
                                ex_to<numeric>(addref.overall_coeff).
                                mul_dyn(ex_to<numeric>(overall_coeff)))
                       )->setflag(status_flags::dynallocated | status_flags::evaluated);
@@ -542,7 +541,7 @@ ex mul::eval(int level) const
                epvector::const_iterator last = seq.end();
                epvector::const_iterator i = seq.begin();
                epvector::const_iterator j = seq.begin();
-               std::auto_ptr<epvector> s(new epvector);
+               epvector s;
                numeric oc = *_num1_p;
                bool something_changed = false;
                while (i!=last) {
@@ -569,12 +568,12 @@ ex mul::eval(int level) const
                        }
 
                        if (! something_changed) {
-                               s->reserve(seq_size);
+                               s.reserve(seq_size);
                                something_changed = true;
                        }
 
                        while ((j!=i) && (j!=last)) {
-                               s->push_back(*j);
+                               s.push_back(*j);
                                ++j;
                        }
 
@@ -592,17 +591,17 @@ ex mul::eval(int level) const
                        for (epvector::iterator ai = primitive->seq.begin(); ai != primitive->seq.end(); ++ai)
                                ai->coeff = ex_to<numeric>(ai->coeff).div_dyn(c);
                        
-                       s->push_back(expair(*primitive, _ex1));
+                       s.push_back(expair(*primitive, _ex1));
 
                        ++i;
                        ++j;
                }
                if (something_changed) {
                        while (j!=last) {
-                               s->push_back(*j);
+                               s.push_back(*j);
                                ++j;
                        }
-                       return (new mul(s, ex_to<numeric>(overall_coeff).mul_dyn(oc))
+                       return (new mul(std::move(s), ex_to<numeric>(overall_coeff).mul_dyn(oc))
                               )->setflag(status_flags::dynallocated);
                }
        }
@@ -618,17 +617,17 @@ ex mul::evalf(int level) const
        if (level==-max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
        
-       std::auto_ptr<epvector> s(new epvector);
-       s->reserve(seq.size());
+       epvector s;
+       s.reserve(seq.size());
 
        --level;
        epvector::const_iterator i = seq.begin(), end = seq.end();
        while (i != end) {
-               s->push_back(combine_ex_with_coeff_to_pair(i->rest.evalf(level),
-                                                          i->coeff));
+               s.push_back(combine_ex_with_coeff_to_pair(i->rest.evalf(level),
+                                                         i->coeff));
                ++i;
        }
-       return mul(s, overall_coeff.evalf(level));
+       return mul(std::move(s), overall_coeff.evalf(level));
 }
 
 void mul::find_real_imag(ex & rp, ex & ip) const
@@ -676,8 +675,8 @@ 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)
-       std::auto_ptr<epvector> s(new epvector);
-       s->reserve(seq.size());
+       epvector s;
+       s.reserve(seq.size());
 
        bool have_matrix = false;
        epvector::iterator the_matrix;
@@ -685,10 +684,10 @@ ex mul::evalm() const
        epvector::const_iterator i = seq.begin(), end = seq.end();
        while (i != end) {
                const ex &m = recombine_pair_to_ex(*i).evalm();
-               s->push_back(split_ex_to_pair(m));
+               s.push_back(split_ex_to_pair(m));
                if (is_a<matrix>(m)) {
                        have_matrix = true;
-                       the_matrix = s->end() - 1;
+                       the_matrix = s.end() - 1;
                }
                ++i;
        }
@@ -698,12 +697,12 @@ ex mul::evalm() const
                // The product contained a matrix. We will multiply all other factors
                // into that matrix.
                matrix m = ex_to<matrix>(the_matrix->rest);
-               s->erase(the_matrix);
-               ex scalar = (new mul(s, overall_coeff))->setflag(status_flags::dynallocated);
+               s.erase(the_matrix);
+               ex scalar = (new mul(std::move(s), overall_coeff))->setflag(status_flags::dynallocated);
                return m.mul_scalar(scalar);
 
        } else
-               return (new mul(s, overall_coeff))->setflag(status_flags::dynallocated);
+               return (new mul(std::move(s), overall_coeff))->setflag(status_flags::dynallocated);
 }
 
 ex mul::eval_ncmul(const exvector & v) const
@@ -994,9 +993,9 @@ ex mul::thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming)
        return (new mul(v, oc, do_index_renaming))->setflag(status_flags::dynallocated);
 }
 
-ex mul::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming) const
+ex mul::thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming) const
 {
-       return (new mul(vp, oc, do_index_renaming))->setflag(status_flags::dynallocated);
+       return (new mul(std::move(vp), oc, do_index_renaming))->setflag(status_flags::dynallocated);
 }
 
 expair mul::split_ex_to_pair(const ex & e) const
@@ -1130,8 +1129,8 @@ ex mul::expand(unsigned options) const
        const bool skip_idx_rename = !(options & expand_options::expand_rename_idx);
 
        // First, expand the children
-       std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
-       const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
+       epvector expanded = expandchildren(options);
+       const epvector & expanded_seq = (expanded.empty() ? seq : expanded);
 
        // 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
@@ -1296,9 +1295,9 @@ ex mul::expand(unsigned options) const
  *  to allow for early cancellations and thus safe memory.
  *
  *  @see mul::expand()
- *  @return pointer to epvector containing expanded representation or zero
- *  pointer, if sequence is unchanged. */
-std::auto_ptr<epvector> mul::expandchildren(unsigned options) const
+ *  @return epvector containing expanded pairs, empty if no members
+ *    had to be changed. */
+epvector mul::expandchildren(unsigned options) const
 {
        const epvector::const_iterator last = seq.end();
        epvector::const_iterator cit = seq.begin();
@@ -1308,31 +1307,31 @@ std::auto_ptr<epvector> mul::expandchildren(unsigned options) const
                if (!are_ex_trivially_equal(factor,expanded_factor)) {
                        
                        // something changed, copy seq, eval and return it
-                       std::auto_ptr<epvector> s(new epvector);
-                       s->reserve(seq.size());
+                       epvector s;
+                       s.reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
                        epvector::const_iterator cit2 = seq.begin();
                        while (cit2!=cit) {
-                               s->push_back(*cit2);
+                               s.push_back(*cit2);
                                ++cit2;
                        }
 
                        // copy first changed element
-                       s->push_back(split_ex_to_pair(expanded_factor));
+                       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)));
+                               s.push_back(split_ex_to_pair(recombine_pair_to_ex(*cit2).expand(options)));
                                ++cit2;
                        }
                        return s;
                }
                ++cit;
        }
-       
-       return std::auto_ptr<epvector>(0); // nothing has changed
+
+       return epvector(); // nothing has changed
 }
 
 GINAC_BIND_UNARCHIVER(mul);
index a2ac691..fb3dd9c 100644 (file)
@@ -42,7 +42,7 @@ public:
        mul(const exvector & v);
        mul(const epvector & v);
        mul(const epvector & v, const ex & oc, bool do_index_renaming = false);
-       mul(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false);
+       mul(epvector && vp, const ex & oc, bool do_index_renaming = false);
        mul(const ex & lh, const ex & mh, const ex & rh);
        
        // functions overriding virtual functions from base classes
@@ -72,7 +72,7 @@ protected:
        unsigned return_type() const;
        return_type_t return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
-       ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
+       ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) 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;
@@ -98,7 +98,7 @@ protected:
        void do_print_csrc(const print_csrc & c, unsigned level) const;
        void do_print_python_repr(const print_python_repr & c, unsigned level) const;
        static bool can_be_further_expanded(const ex & e);
-       std::auto_ptr<epvector> expandchildren(unsigned options) const;
+       epvector expandchildren(unsigned options) const;
 };
 GINAC_DECLARE_UNARCHIVER(mul);
 
index 797ccea..512edf2 100644 (file)
@@ -84,7 +84,7 @@ ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable)
 {
 }
 
-ncmul::ncmul(std::auto_ptr<exvector> vp) : inherited(vp)
+ncmul::ncmul(exvector && v) : inherited(std::move(v))
 {
 }
 
@@ -120,8 +120,8 @@ typedef std::vector<std::size_t> uintvector;
 ex ncmul::expand(unsigned options) const
 {
        // First, expand the children
-       std::auto_ptr<exvector> vp = expandchildren(options);
-       const exvector &expanded_seq = vp.get() ? *vp : this->seq;
+       exvector v = expandchildren(options);
+       const exvector &expanded_seq = v.empty() ? this->seq : v;
        
        // Now, look for all the factors that are sums and remember their
        // position and number of terms.
@@ -146,8 +146,8 @@ ex ncmul::expand(unsigned options) const
 
        // If there are no sums, we are done
        if (number_of_adds == 0) {
-               if (vp.get())
-                       return (new ncmul(vp))->
+               if (!v.empty())
+                       return (new ncmul(std::move(v)))->
                                setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
                else
                        return *this;
@@ -447,16 +447,16 @@ ex ncmul::eval(int level) const
 ex ncmul::evalm() const
 {
        // Evaluate children first
-       std::auto_ptr<exvector> s(new exvector);
-       s->reserve(seq.size());
+       exvector s;
+       s.reserve(seq.size());
        exvector::const_iterator it = seq.begin(), itend = seq.end();
        while (it != itend) {
-               s->push_back(it->evalm());
+               s.push_back(it->evalm());
                it++;
        }
 
        // If there are only matrices, simply multiply them
-       it = s->begin(); itend = s->end();
+       it = s.begin(); itend = s.end();
        if (is_a<matrix>(*it)) {
                matrix prod(ex_to<matrix>(*it));
                it++;
@@ -470,7 +470,7 @@ ex ncmul::evalm() const
        }
 
 no_matrix:
-       return (new ncmul(s))->setflag(status_flags::dynallocated);
+       return (new ncmul(std::move(s)))->setflag(status_flags::dynallocated);
 }
 
 ex ncmul::thiscontainer(const exvector & v) const
@@ -478,9 +478,9 @@ ex ncmul::thiscontainer(const exvector & v) const
        return (new ncmul(v))->setflag(status_flags::dynallocated);
 }
 
-ex ncmul::thiscontainer(std::auto_ptr<exvector> vp) const
+ex ncmul::thiscontainer(exvector && v) const
 {
-       return (new ncmul(vp))->setflag(status_flags::dynallocated);
+       return (new ncmul(std::move(v)))->setflag(status_flags::dynallocated);
 }
 
 ex ncmul::conjugate() const
@@ -596,7 +596,7 @@ return_type_t ncmul::return_type_tinfo() const
 // non-virtual functions in this class
 //////////
 
-std::auto_ptr<exvector> ncmul::expandchildren(unsigned options) const
+exvector ncmul::expandchildren(unsigned options) const
 {
        const_iterator cit = this->seq.begin(), end = this->seq.end();
        while (cit != end) {
@@ -604,16 +604,16 @@ std::auto_ptr<exvector> ncmul::expandchildren(unsigned options) const
                if (!are_ex_trivially_equal(*cit, expanded_ex)) {
 
                        // copy first part of seq which hasn't changed
-                       std::auto_ptr<exvector> s(new exvector(this->seq.begin(), cit));
-                       reserve(*s, this->seq.size());
+                       exvector s(this->seq.begin(), cit);
+                       s.reserve(this->seq.size());
 
                        // insert changed element
-                       s->push_back(expanded_ex);
+                       s.push_back(expanded_ex);
                        ++cit;
 
                        // copy rest
                        while (cit != end) {
-                               s->push_back(cit->expand(options));
+                               s.push_back(cit->expand(options));
                                ++cit;
                        }
 
@@ -623,7 +623,7 @@ std::auto_ptr<exvector> ncmul::expandchildren(unsigned options) const
                ++cit;
        }
 
-       return std::auto_ptr<exvector>(0); // nothing has changed
+       return exvector(); // nothing has changed
 }
 
 const exvector & ncmul::get_factors() const
index 02ee0dc..8e68054 100644 (file)
@@ -50,7 +50,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(std::auto_ptr<exvector> vp);
+       ncmul(exvector && v);
 
        // functions overriding virtual functions from base classes
 public:
@@ -64,7 +64,7 @@ public:
        ex evalm() const;
        exvector get_free_indices() const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex thiscontainer(exvector && v) const;
        ex conjugate() const;
        ex real_part() const;
        ex imag_part() const;
@@ -83,7 +83,7 @@ protected:
        void do_print_csrc(const print_context & c, unsigned level) const;
        size_t count_factors(const ex & e) const;
        void append_factors(exvector & v, const ex & e) const;
-       std::auto_ptr<exvector> expandchildren(unsigned options) const;
+       exvector expandchildren(unsigned options) const;
 public:
        const exvector & get_factors() const;
 };
index 464ecac..18b4637 100644 (file)
@@ -2587,10 +2587,10 @@ ex expairseq::to_rational(exmap & repl) const
        }
        ex oc = overall_coeff.to_rational(repl);
        if (oc.info(info_flags::numeric))
-               return thisexpairseq(s, overall_coeff);
+               return thisexpairseq(std::move(s), overall_coeff);
        else
                s.push_back(combine_ex_with_coeff_to_pair(oc, _ex1));
-       return thisexpairseq(s, default_overall_coeff());
+       return thisexpairseq(std::move(s), default_overall_coeff());
 }
 
 /** Implementation of ex::to_polynomial() for expairseqs. */
@@ -2605,10 +2605,10 @@ ex expairseq::to_polynomial(exmap & repl) const
        }
        ex oc = overall_coeff.to_polynomial(repl);
        if (oc.info(info_flags::numeric))
-               return thisexpairseq(s, overall_coeff);
+               return thisexpairseq(std::move(s), overall_coeff);
        else
                s.push_back(combine_ex_with_coeff_to_pair(oc, _ex1));
-       return thisexpairseq(s, default_overall_coeff());
+       return thisexpairseq(std::move(s), default_overall_coeff());
 }
 
 
index 4a56da8..47050dd 100644 (file)
@@ -238,9 +238,9 @@ private:
  *  implements the actual function call. */
 class print_functor {
 public:
-       print_functor() : impl(0) {}
+       print_functor() : impl(nullptr) {}
        print_functor(const print_functor & other) : impl(other.impl.get() ? other.impl->duplicate() : 0) {}
-       print_functor(std::auto_ptr<print_functor_impl> impl_) : impl(impl_) {}
+       print_functor(std::unique_ptr<print_functor_impl> impl_) : impl(std::move(impl_)) {}
 
        template <class T, class C>
        print_functor(void f(const T &, const C &, unsigned)) : impl(new print_ptrfun_handler<T, C>(f)) {}
@@ -265,7 +265,7 @@ public:
        bool is_valid() const { return impl.get(); }
 
 private:
-       std::auto_ptr<print_functor_impl> impl;
+       std::unique_ptr<print_functor_impl> impl;
 };