#include <algorithm>
#include <vector>
#include <list>
+#include <memory>
#include "ex.h"
#include "print.h"
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)
/** 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,
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 */
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);
}
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
- // (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) {
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
++cit;
}
- return 0; // nothing has changed
+ return std::auto_ptr<STLT>(0); // nothing has changed
}
} // namespace GiNaC