]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.h
Remove deprecated initialization via overloaded comma operator.
[ginac.git] / ginac / container.h
index 11b5be0bbec78740b15b2d15dd5d0b68a71eb894..6c312e74556ac9030bfe1e8d1646562f8c349427 100644 (file)
@@ -3,7 +3,7 @@
  *  Wrapper template for making GiNaC classes out of STL containers. */
 
 /*
- *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef __GINAC_CONTAINER_H__
-#define __GINAC_CONTAINER_H__
-
-#include <iterator>
-#include <stdexcept>
-#include <algorithm>
-#include <vector>
-#include <list>
-#include <memory>
+#ifndef GINAC_CONTAINER_H
+#define GINAC_CONTAINER_H
 
 #include "ex.h"
 #include "print.h"
 #include "archive.h"
 #include "assertion.h"
+#include "compiler.h"
 
-namespace GiNaC {
+#include <algorithm>
+#include <iterator>
+#include <list>
+#include <memory>
+#include <stdexcept>
+#include <vector>
 
+namespace GiNaC {
 
 /** Helper template for encapsulating the reserve() mechanics of STL containers. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 class container_storage {
 protected:
        typedef C<ex> STLT;
 
        container_storage() {}
        container_storage(size_t n, const ex & e) : seq(n, e) {}
+       container_storage(std::initializer_list<ex> il) : seq(il) {}
 
        template <class In>
        container_storage(In b, In e) : seq(b, e) {}
@@ -67,68 +68,11 @@ template <>
 inline void container_storage<std::vector>::reserve(std::vector<ex> & v, size_t n) { v.reserve(n); }
 
 
-/** Helper template to allow initialization of containers via an overloaded
- *  comma operator (idea stolen from Blitz++). */
-template <typename T, typename STLT>
-class container_init {
-public:
-       container_init(STLT & s) : stlt(s) {}
-
-       container_init<T, STLT> operator,(const T & x)
-       {
-               stlt.push_back(x);
-               return container_init<T, STLT>(stlt);
-       }
-
-       // The following specializations produce much tighter code than the
-       // general case above
-
-       container_init<T, STLT> operator,(int x)
-       {
-               stlt.push_back(x);
-               return container_init<T, STLT>(stlt);
-       }
-
-       container_init<T, STLT> operator,(unsigned int x)
-       {
-               stlt.push_back(x);
-               return container_init<T, STLT>(stlt);
-       }
-
-       container_init<T, STLT> operator,(long x)
-       {
-               stlt.push_back(x);
-               return container_init<T, STLT>(stlt);
-       }
-
-       container_init<T, STLT> operator,(unsigned long x)
-       {
-               stlt.push_back(x);
-               return container_init<T, STLT>(stlt);
-       }
-
-       container_init<T, STLT> operator,(double x)
-       {
-               stlt.push_back(x);
-               return container_init<T, STLT>(stlt);
-       }
-
-       container_init<T, STLT> operator,(const symbol & x)
-       {
-               stlt.push_back(T(x));
-               return container_init<T, STLT>(stlt);
-       }
-
-private:
-       container_init();
-       STLT & stlt;
-};
-
 /** Wrapper template for making GiNaC classes out of STL containers. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 class container : public basic, public container_storage<C> {
        GINAC_DECLARE_REGISTERED_CLASS(container, basic)
-
+protected:
        typedef typename container_storage<C>::STLT STLT;
 
 public:
@@ -137,239 +81,72 @@ public:
 
 protected:
        // helpers
-       static unsigned get_tinfo() { return TINFO_fail; }
        static unsigned get_default_flags() { return 0; }
        static char get_open_delim() { return '('; }
        static char get_close_delim() { return ')'; }
 
        // constructors
 public:
-       container(STLT const & s, bool discardable = false) : inherited(get_tinfo())
+       container(STLT const & s)
        {
                setflag(get_default_flags());
-
-               if (discardable)
-                       this->seq.swap(const_cast<STLT &>(s));
-               else
-                       this->seq = s;
+               this->seq = s;
        }
 
-       explicit container(std::auto_ptr<STLT> vp) : inherited(get_tinfo())
+       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)
-        : inherited(get_tinfo()), container_storage<C>(b, e)
-       {
-               setflag(get_default_flags());
-       }
-
-       explicit container(const ex & p1)
-        : inherited(get_tinfo()), container_storage<C>(1, p1)
-       {
-               setflag(get_default_flags());
-       }
-
-       container(const ex & p1, const ex & p2) : inherited(get_tinfo())
+        : container_storage<C>(b, e)
        {
                setflag(get_default_flags());
-               reserve(this->seq, 2);
-               this->seq.push_back(p1); this->seq.push_back(p2);
        }
 
-       container(const ex & p1, const ex & p2, const ex & p3) : inherited(get_tinfo())
+       container(std::initializer_list<ex> il)
+        : container_storage<C>(il)
        {
                setflag(get_default_flags());
-               reserve(this->seq, 3);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
        }
 
-       container(const ex & p1, const ex & p2, const ex & p3,
-                          const ex & p4) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 4);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 5);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 6);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 7);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 8);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 9);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 10);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10, const ex & p11) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 11);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10); this->seq.push_back(p11);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10, const ex & p11, const ex & p12) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 12);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10); this->seq.push_back(p11); this->seq.push_back(p12);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10, const ex & p11, const ex & p12,
-                 const ex & p13) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 13);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10); this->seq.push_back(p11); this->seq.push_back(p12);
-               this->seq.push_back(p13);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10, const ex & p11, const ex & p12,
-                 const ex & p13, const ex & p14) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 14);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10); this->seq.push_back(p11); this->seq.push_back(p12);
-               this->seq.push_back(p13); this->seq.push_back(p14);
-       }
-
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10, const ex & p11, const ex & p12,
-                 const ex & p13, const ex & p14, const ex & p15) : inherited(get_tinfo())
+       // functions overriding virtual functions from base classes
+public:
+       bool info(unsigned inf) const override { return inherited::info(inf); }
+       unsigned precedence() const override { return 10; }
+       size_t nops() const override { return this->seq.size(); }
+       ex op(size_t i) const override;
+       ex & let_op(size_t i) override;
+       ex subs(const exmap & m, unsigned options = 0) const override;
+
+       void read_archive(const archive_node &n, lst &sym_lst) override
        {
+               inherited::read_archive(n, sym_lst);
                setflag(get_default_flags());
-               reserve(this->seq, 15);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10); this->seq.push_back(p11); this->seq.push_back(p12);
-               this->seq.push_back(p13); this->seq.push_back(p14); this->seq.push_back(p15);
-       }
 
-       container(const ex & p1, const ex & p2, const ex & p3,
-                 const ex & p4, const ex & p5, const ex & p6,
-                 const ex & p7, const ex & p8, const ex & p9,
-                 const ex & p10, const ex & p11, const ex & p12,
-                 const ex & p13, const ex & p14, const ex & p15,
-                 const ex & p16) : inherited(get_tinfo())
-       {
-               setflag(get_default_flags());
-               reserve(this->seq, 16);
-               this->seq.push_back(p1); this->seq.push_back(p2); this->seq.push_back(p3);
-               this->seq.push_back(p4); this->seq.push_back(p5); this->seq.push_back(p6);
-               this->seq.push_back(p7); this->seq.push_back(p8); this->seq.push_back(p9);
-               this->seq.push_back(p10); this->seq.push_back(p11); this->seq.push_back(p12);
-               this->seq.push_back(p13); this->seq.push_back(p14); this->seq.push_back(p15);
-               this->seq.push_back(p16);
+               auto range =  n.find_property_range("seq", "seq");
+               this->reserve(this->seq, range.end - range.begin);
+               for (archive_node::archive_node_cit i=range.begin; i<range.end; ++i) {
+                       ex e;
+                       n.find_ex_by_loc(i, e, sym_lst);
+                       this->seq.emplace_back(e);
+               }
        }
 
-       // First step of initialization of container with a comma-separated
-       // sequence of expressions. Subsequent steps are handled by
-       // container_init<>::operator,().
-       container_init<ex, STLT> operator=(const ex & x)
+       /** Archive the object. */
+       void archive(archive_node &n) const override
        {
-               this->seq.push_back(x);
-               return container_init<ex, STLT>(this->seq);
+               inherited::archive(n);
+               for (auto & i : this->seq) {
+                       n.add_ex("seq", i);
+               }
        }
 
-       // functions overriding virtual functions from base classes
-public:
-       bool info(unsigned inf) const { return inherited::info(inf); }
-       unsigned precedence() const { return 10; }
-       size_t nops() const { return this->seq.size(); }
-       ex op(size_t i) const;
-       ex & let_op(size_t i);
-       ex eval(int level = 0) const;
-       ex subs(const exmap & m, unsigned options = 0) const;
-
 protected:
-       ex conjugate() const
+       ex conjugate() const override
        {
-               STLT *newcont = NULL;
+               STLT *newcont = nullptr;
                for (const_iterator i=this->seq.begin(); i!=this->seq.end(); ++i) {
                        if (newcont) {
                                newcont->push_back(i->conjugate());
@@ -380,7 +157,7 @@ protected:
                                continue;
                        }
                        newcont = new STLT;
-                       reserve(*newcont, this->seq.size());
+                       this->reserve(*newcont, this->seq.size());
                        for (const_iterator j=this->seq.begin(); j!=i; ++j) {
                                newcont->push_back(*j);
                        }
@@ -394,7 +171,29 @@ protected:
                return *this;
        }
 
-       bool is_equal_same_type(const basic & other) const;
+       ex real_part() const override
+       {
+               STLT cont;
+               this->reserve(cont, nops());
+               const_iterator b = begin();
+               const_iterator e = end();
+               for(const_iterator i=b; i!=e; ++i)
+                       cont.push_back(i->real_part());
+               return thiscontainer(cont);
+       }
+
+       ex imag_part() const override
+       {
+               STLT cont;
+               this->reserve(cont, nops());
+               const_iterator b = begin();
+               const_iterator e = end();
+               for(const_iterator i=b; i!=e; ++i)
+                       cont.push_back(i->imag_part());
+               return thiscontainer(cont);
+       }
+
+       bool is_equal_same_type(const basic & other) const override;
 
        // new virtual functions which can be overridden by derived classes
 protected:
@@ -403,8 +202,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,
@@ -447,62 +246,27 @@ protected:
        void do_print_tree(const print_tree & c, unsigned 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;
-       std::auto_ptr<STLT> subschildren(const exmap & m, unsigned options = 0) const;
+       STLT subschildren(const exmap & m, unsigned options = 0) const;
 };
 
 /** Default constructor */
-template <template <class> class C>
-container<C>::container() : inherited(get_tinfo())
-{
-       setflag(get_default_flags());
-}
-
-/** Construct object from archive_node. */
-template <template <class> class C>
-container<C>::container(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
+template <template <class T, class = std::allocator<T>> class C>
+container<C>::container()
 {
        setflag(get_default_flags());
-
-       for (unsigned int i=0; true; i++) {
-               ex e;
-               if (n.find_ex("seq", e, sym_lst, i))
-                       this->seq.push_back(e);
-               else
-                       break;
-       }
 }
 
-/** Unarchive the object. */
-template <template <class> class C>
-ex container<C>::unarchive(const archive_node &n, lst &sym_lst)
-{
-       return (new container(n, sym_lst))->setflag(status_flags::dynallocated);
-}
-
-/** Archive the object. */
-template <template <class> class C>
-void container<C>::archive(archive_node &n) const
-{
-       inherited::archive(n);
-       const_iterator i = this->seq.begin(), end = this->seq.end();
-       while (i != end) {
-               n.add_ex("seq", *i);
-               ++i;
-       }
-}
-
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 void container<C>::do_print(const print_context & c, unsigned level) const
 {
        // always print brackets around seq, ignore upper_precedence
        printseq(c, get_open_delim(), ',', get_close_delim(), precedence(), precedence()+1);
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 void container<C>::do_print_tree(const print_tree & c, unsigned level) const
 {
-       c.s << std::string(level, ' ') << class_name()
+       c.s << std::string(level, ' ') << class_name() << " @" << this
            << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
            << ", nops=" << nops()
            << std::endl;
@@ -514,20 +278,20 @@ void container<C>::do_print_tree(const print_tree & c, unsigned level) const
        c.s << std::string(level + c.delta_indent,' ') << "=====" << std::endl;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 void container<C>::do_print_python(const print_python & c, unsigned level) const
 {
        printseq(c, '[', ',', ']', precedence(), precedence()+1);
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 void container<C>::do_print_python_repr(const print_python_repr & c, unsigned level) const
 {
        c.s << class_name();
        printseq(c, '(', ',', ')', precedence(), precedence()+1);
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 ex container<C>::op(size_t i) const
 {
        GINAC_ASSERT(i < nops());
@@ -537,7 +301,7 @@ ex container<C>::op(size_t i) const
        return *it;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 ex & container<C>::let_op(size_t i)
 {
        GINAC_ASSERT(i < nops());
@@ -548,27 +312,34 @@ ex & container<C>::let_op(size_t i)
        return *it;
 }
 
-template <template <class> class C>
-ex container<C>::eval(int level) const
-{
-       if (level == 1)
-               return hold();
-       else
-               return thiscontainer(evalchildren(level));
-}
-
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 ex container<C>::subs(const exmap & m, unsigned options) const
 {
-       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);
+       // After having subs'ed all children, this method subs'es one final
+       // level, but only if the intermediate result is a container! This is
+       // because if the intermediate result has eval'ed to a non-container a
+       // last level substitution would be wrong, as this example involving a
+       // function f and its inverse f^-1 shows:
+       // f(x).subs(x==f^-1(x))
+       //   -> f(f^-1(x))  [subschildren]
+       //   -> x           [eval]   /* must not subs(x==f^-1(x))! */
+       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
+                       return result;
+       } else {
+               if (is_a<container<C>>(*this))
+                       return subs_one_level(m, options);
+               else
+                       return *this;
+       }
 }
 
 /** Compare two containers of the same type. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 int container<C>::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<container>(other));
@@ -587,7 +358,7 @@ int container<C>::compare_same_type(const basic & other) const
        return (it1 == it1end) ? (it2 == it2end ? 0 : -1) : 1;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 bool container<C>::is_equal_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<container>(other));
@@ -607,7 +378,7 @@ bool container<C>::is_equal_same_type(const basic & other) const
 }
 
 /** Add element at front. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::prepend(const ex & b)
 {
        ensure_if_modifiable();
@@ -616,7 +387,7 @@ container<C> & container<C>::prepend(const ex & b)
 }
 
 /** Add element at back. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::append(const ex & b)
 {
        ensure_if_modifiable();
@@ -625,7 +396,7 @@ container<C> & container<C>::append(const ex & b)
 }
 
 /** Remove first element. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::remove_first()
 {
        ensure_if_modifiable();
@@ -634,7 +405,7 @@ container<C> & container<C>::remove_first()
 }
 
 /** Remove last element. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::remove_last()
 {
        ensure_if_modifiable();
@@ -643,7 +414,7 @@ container<C> & container<C>::remove_last()
 }
 
 /** Remove all elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::remove_all()
 {
        ensure_if_modifiable();
@@ -652,7 +423,7 @@ container<C> & container<C>::remove_all()
 }
 
 /** Sort elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::sort()
 {
        ensure_if_modifiable();
@@ -667,7 +438,7 @@ template<> inline void container<std::list>::unique_()
 }
 
 /** Remove adjacent duplicate elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 container<C> & container<C>::unique()
 {
        ensure_if_modifiable();
@@ -676,7 +447,7 @@ container<C> & container<C>::unique()
 }
 
 /** Print sequence of contained elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T>> class C>
 void container<C>::printseq(const print_context & c, char openbracket, char delim,
                             char closebracket, unsigned this_precedence,
                             unsigned upper_precedence) const
@@ -699,33 +470,11 @@ void container<C>::printseq(const print_context & c, char openbracket, char deli
                c.s << closebracket;
 }
 
-template <template <class> class C>
-typename container<C>::STLT container<C>::evalchildren(int level) const
-{
-       if (level == 1)
-               return this->seq;
-       else if (level == -max_recursion_level)
-               throw std::runtime_error("max recursion level reached");
-
-       STLT s;
-       reserve(s, this->seq.size());
-
-       --level;
-       const_iterator it = this->seq.begin(), itend = this->seq.end();
-       while (it != itend) {
-               s.push_back(it->eval(level));
-               ++it;
-       }
-
-       return s;
-}
-
-template <template <class> class C>
-std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exmap & m, unsigned options) const
+template <template <class T, class = std::allocator<T>> class C>
+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
-       // (and relinquishes responsibility for the epvector)
+       // 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) {
@@ -733,16 +482,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));
-                       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;
                        }
 
@@ -752,9 +501,9 @@ 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
 
-#endif // ndef __GINAC_CONTAINER_H__
+#endif // ndef GINAC_CONTAINER_H