]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.pl
- indentation is now done with tabs
[ginac.git] / ginac / container.pl
index 4f838e6802ced17bc7569c602b0fd0a99193525f..9dac1847530c3797ec530fcb5b68e5873ac340ee 100755 (executable)
@@ -1,7 +1,5 @@
-#!/usr/bin/perl -w
-
-if ($#ARGV!=0) {
-    die 'usage: container.pl type (type=lst or exprseq)';
+if (($#ARGV!=0) and ($#ARGV!=1)) {
+    die 'usage: container.pl type [maxargs] (type=lst or exprseq)';
 }
 
 if ($ARGV[0] eq 'lst') {
@@ -12,8 +10,11 @@ if ($ARGV[0] eq 'lst') {
     die 'only lst and exprseq supported';
 }
 
-#$type='lst';
-#$type='exprseq';
+if ($#ARGV==1) {
+    $maxargs=$ARGV[1];
+} else {
+    $maxargs=15; # must be greater or equal than the value used in function.pl
+}
 
 if ($type eq 'exprseq') {
 
@@ -52,11 +53,11 @@ if ($reserve) {
 
 if ($prepend) {
     $PREPEND_INTERFACE=<<END_OF_PREPEND_INTERFACE;
-    virtual ${CONTAINER} & prepend(ex const & b);
+    virtual ${CONTAINER} & prepend(const ex & b);
 END_OF_PREPEND_INTERFACE
 
     $PREPEND_IMPLEMENTATION=<<END_OF_PREPEND_IMPLEMENTATION;
-${CONTAINER} & ${CONTAINER}::prepend(ex const & b)
+${CONTAINER} & ${CONTAINER}::prepend(const ex & b)
 {
     ensure_if_modifiable();
     seq.push_front(b);
@@ -70,10 +71,10 @@ END_OF_PREPEND_IMPLEMENTATION
 
 if ($let_op) {
     $LET_OP_IMPLEMENTATION=<<END_OF_LET_OP_IMPLEMENTATION
-ex & ${CONTAINER}::let_op(int const i)
+ex & ${CONTAINER}::let_op(int i)
 {
-    ASSERT(i>=0);
-    ASSERT(i<nops());
+    GINAC_ASSERT(i>=0);
+    GINAC_ASSERT(i<nops());
 
     ${STLT}::iterator it=seq.begin();
     for (int j=0; j<i; j++) {
@@ -86,10 +87,63 @@ END_OF_LET_OP_IMPLEMENTATION
     $LET_OP_IMPLEMENTATION="// ${CONTAINER}::let_op() will be implemented by user elsewhere";
 }
 
+sub generate_seq {
+    my ($seq_template,$n,$separator)=@_;
+    my ($res,$N);
+    
+    $res='';
+    for ($N=1; $N<=$n; $N++) {
+        $res .= eval('"' . $seq_template . '"');
+        if ($N!=$n) {
+            $res .= $separator;
+        }
+    }
+    return $res;
+}
+
+sub generate_from_to {
+    my ($template,$seq_template1,$seq_separator1,$seq_template2,
+        $seq_separator2,$from,$to)=@_;
+    my ($res,$N,$SEQ);
+
+    $res='';
+    for ($N=$from; $N<=$to; $N++) {
+        $SEQ1=generate_seq($seq_template1,$N,$seq_separator1);
+        $SEQ2=generate_seq($seq_template2,$N,$seq_separator2);
+        $res .= eval('"' . $template . '"');
+        $SEQ1=''; # to avoid main::SEQ1 used only once warning
+        $SEQ2=''; # same as above
+    }
+    return $res;
+}
+
+sub generate {
+    my ($template,$seq_template1,$seq_separator1,$seq_template2,
+        $seq_separator2)=@_;
+    return generate_from_to($template,$seq_template1,$seq_separator1,
+                            $seq_template2,$seq_separator2,1,$maxargs);
+}
+
+$constructors_interface=generate(
+'    explicit ${CONTAINER}(${SEQ1});'."\n",
+'const ex & param${N}',', ','','');
+
+$constructors_implementation=generate(
+    <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ','    seq.push_back(param${N});',"\n");
+${CONTAINER}::${CONTAINER}(${SEQ1}) : basic(TINFO_${CONTAINER})
+{
+    debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
+    RESERVE(seq,${N});
+${SEQ2}
+}
+END_OF_CONSTRUCTORS_IMPLEMENTATION
+
 $interface=<<END_OF_INTERFACE;
 /** \@file ${CONTAINER}.h
  *
- *  Definition of GiNaC's ${CONTAINER}. 
+ *  Definition of GiNaC's ${CONTAINER}. */
+
+/*
  *  This file was generated automatically by container.pl.
  *  Please do not modify it directly, edit the perl script instead!
  *  container.pl options: \$CONTAINER=${CONTAINER}
@@ -99,8 +153,9 @@ $interface=<<END_OF_INTERFACE;
  *                        \$let_op=${let_op}
  *                        \$open_bracket=${open_bracket}
  *                        \$close_bracket=${close_bracket}
+ *                        \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 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
@@ -121,12 +176,23 @@ $interface=<<END_OF_INTERFACE;
 #define __GINAC_${CONTAINER_UC}_H__
 
 #include <${STLHEADER}>
-#include <ginac/basic.h>
 
-typedef ${STLHEADER}<ex> ${STLT};
+// CINT needs <algorithm> to work properly with <vector> and <list> 
+#include <algorithm>
+
+#include "basic.h"
+#include "ex.h"
+
+#ifndef NO_NAMESPACE_GINAC
+namespace GiNaC {
+#endif // ndef NO_NAMESPACE_GINAC
+
+// typedef std::${STLHEADER}<ex> ${STLT};
+typedef std::${STLHEADER}<ex,malloc_alloc> ${STLT}; // CINT does not like ${STLHEADER}<...,default_alloc>
 
 class ${CONTAINER} : public basic
 {
+    GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
 
 public:
     ${CONTAINER}();
@@ -140,55 +206,34 @@ protected:
 public:
     ${CONTAINER}(${STLT} const & s, bool discardable=0);
     ${CONTAINER}(${STLT} * vp); // vp will be deleted
-    explicit ${CONTAINER}(ex const & e1);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4, ex const & e5);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4, ex const & e5, ex const & e6);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4, ex const & e5, ex const & e6,
-             ex const & e7);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4, ex const & e5, ex const & e6,
-             ex const & e7, ex const & e8);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4, ex const & e5, ex const & e6,
-             ex const & e7, ex const & e8, ex const & e9);
-    explicit ${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-             ex const & e4, ex const & e5, ex const & e6,
-             ex const & e7, ex const & e8, ex const & e9,
-             ex const &e10);
+${constructors_interface}
 
 public:
     basic * duplicate() const;
-    void printraw(ostream & os) const;
-    void print(ostream & os, unsigned upper_precedence=0) const;
-    void printtree(ostream & os, unsigned indent) const;
+    void printraw(std::ostream & os) const;
+    void print(std::ostream & os, unsigned upper_precedence=0) const;
+    void printtree(std::ostream & os, unsigned indent) const;
     bool info(unsigned inf) const;
-    int nops() const;
-    ex & let_op(int const i);
+    unsigned nops() const;
+    ex & let_op(int i);
     ex expand(unsigned options=0) const;
-    bool has(ex const & other) const;
+    bool has(const ex & other) const;
     ex eval(int level=0) const;
     ex evalf(int level=0) const;
     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
-    ex diff(symbol const & s) const;
-    ex subs(lst const & ls, lst const & lr) const;
+    ex derivative(const symbol & s) const;
+    ex subs(const lst & ls, const lst & lr) const;
 protected:
-    int compare_same_type(basic const & other) const;
-    bool is_equal_same_type(basic const & other) const;
+    int compare_same_type(const basic & other) const;
+    bool is_equal_same_type(const basic & other) const;
     unsigned return_type(void) const;
 
     // new virtual functions which can be overridden by derived classes
 public:
-    virtual ${CONTAINER} & append(ex const & b);
+    virtual ${CONTAINER} & append(const ex & b);
 ${PREPEND_INTERFACE}
 protected:
-    virtual void printseq(ostream & os, char openbracket, char delim,
+    virtual void printseq(std::ostream & os, char openbracket, char delim,
                           char closebracket, unsigned this_precedence,
                           unsigned upper_precedence=0) const;
     virtual ex this${CONTAINER}(${STLT} const & v) const;
@@ -199,8 +244,8 @@ protected:
     ${STLT} evalchildren(int level) const;
     ${STLT} evalfchildren(int level) const;
     ${STLT} normalchildren(int level) const;
-    ${STLT} diffchildren(symbol const & s) const;
-    ${STLT} * subschildren(lst const & ls, lst const & lr) const;
+    ${STLT} diffchildren(const symbol & s) const;
+    ${STLT} * subschildren(const lst & ls, const lst & lr) const;
 
 protected:
     ${STLT} seq;
@@ -210,11 +255,22 @@ protected:
 // global constants
 
 extern const ${CONTAINER} some_${CONTAINER};
-extern type_info const & typeid_${CONTAINER};
+extern const type_info & typeid_${CONTAINER};
 
-// macros
+// utility functions
+inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e)
+{
+    return static_cast<const ${CONTAINER} &>(*e.bp);
+}
 
-#define ex_to_${CONTAINER}(X) (static_cast<${CONTAINER} const &>(*(X).bp))
+inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e)
+{
+    return static_cast<${CONTAINER} &>(*e.bp);
+}
+
+#ifndef NO_NAMESPACE_GINAC
+} // namespace GiNaC
+#endif // ndef NO_NAMESPACE_GINAC
 
 #endif // ndef __GINAC_${CONTAINER_UC}_H__
 
@@ -223,7 +279,9 @@ END_OF_INTERFACE
 $implementation=<<END_OF_IMPLEMENTATION;
 /** \@file ${CONTAINER}.cpp
  *
- *  Implementation of GiNaC's ${CONTAINER}. 
+ *  Implementation of GiNaC's ${CONTAINER}. */
+
+/*
  *  This file was generated automatically by container.pl.
  *  Please do not modify it directly, edit the perl script instead!
  *  container.pl options: \$CONTAINER=${CONTAINER}
@@ -233,8 +291,9 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *                        \$let_op=${let_op}
  *                        \$open_bracket=${open_bracket}
  *                        \$close_bracket=${close_bracket}
+ *                        \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 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
@@ -256,6 +315,14 @@ $implementation=<<END_OF_IMPLEMENTATION;
 
 #include "${CONTAINER}.h"
 #include "ex.h"
+#include "archive.h"
+#include "debugmsg.h"
+
+#ifndef NO_NAMESPACE_GINAC
+namespace GiNaC {
+#endif // ndef NO_NAMESPACE_GINAC
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(${CONTAINER}, basic)
 
 ${RESERVE_IMPLEMENTATION}
 
@@ -296,14 +363,14 @@ ${CONTAINER} const & ${CONTAINER}::operator=(${CONTAINER} const & other)
 
 void ${CONTAINER}::copy(${CONTAINER} const & other)
 {
-    basic::copy(other);
+    inherited::copy(other);
     seq=other.seq;
 }
 
 void ${CONTAINER}::destroy(bool call_parent)
 {
     seq.clear();
-    if (call_parent) basic::destroy(call_parent);
+    if (call_parent) inherited::destroy(call_parent);
 }
 
 //////////
@@ -326,150 +393,45 @@ ${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) :  basic(TINFO_$
 ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
 {
     debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
-    ASSERT(vp!=0);
+    GINAC_ASSERT(vp!=0);
     seq.swap(*vp);
     delete vp;
 }
 
-${CONTAINER}::${CONTAINER}(ex const & e1) :  basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 1 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,1);
-    seq.push_back(e1);
-}
-
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 2 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,2);
-    seq.push_back(e1);
-    seq.push_back(e2);
-}
+${constructors_implementation}
 
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 3 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,3);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-}
-
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 4 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,4);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-}
-
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4, ex const & e5) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 5 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,5);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-}
+//////////
+// archiving
+//////////
 
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4, ex const & e5, ex const & e6)
-    : basic(TINFO_${CONTAINER})
+/** Construct object from archive_node. */
+${CONTAINER}::${CONTAINER}(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
-    debugmsg("${CONTAINER} constructor from 6 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,6);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
+    debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT);
+    for (unsigned int i=0; true; i++) {
+        ex e;
+        if (n.find_ex("seq", e, sym_lst, i))
+            seq.push_back(e);
+        else
+            break;
+    }
 }
 
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4, ex const & e5, ex const & e6,
-                     ex const & e7) : basic(TINFO_${CONTAINER})
+/** Unarchive the object. */
+ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst)
 {
-    debugmsg("${CONTAINER} constructor from 7 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,7);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
+    return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated);
 }
 
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4, ex const & e5, ex const & e6,
-                     ex const & e7, ex const & e8) : basic(TINFO_${CONTAINER})
+/** Archive the object. */
+void ${CONTAINER}::archive(archive_node &n) const
 {
-    debugmsg("${CONTAINER} constructor from 8 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,8);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-    seq.push_back(e8);
-}
-
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4, ex const & e5, ex const & e6,
-                     ex const & e7, ex const & e8, ex const & e9)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 9 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,9);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-    seq.push_back(e8);
-    seq.push_back(e9);
-}
-
-${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
-                     ex const & e4, ex const & e5, ex const & e6,
-                     ex const & e7, ex const & e8, ex const & e9,
-                     ex const &e10)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 10 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,10);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-    seq.push_back(e8);
-    seq.push_back(e9);
-    seq.push_back(e10);
+    inherited::archive(n);
+    ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
+    while (i != iend) {
+        n.add_ex("seq", *i);
+        i++;
+    }
 }
 
 //////////
@@ -484,7 +446,7 @@ basic * ${CONTAINER}::duplicate() const
     return new ${CONTAINER}(*this);
 }
 
-void ${CONTAINER}::printraw(ostream & os) const
+void ${CONTAINER}::printraw(std::ostream & os) const
 {
     debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
 
@@ -496,30 +458,31 @@ void ${CONTAINER}::printraw(ostream & os) const
     os << ")";
 }
 
-void ${CONTAINER}::print(ostream & os, unsigned upper_precedence) const
+void ${CONTAINER}::print(std::ostream & os, unsigned upper_precedence) const
 {
     debugmsg("${CONTAINER} print",LOGLEVEL_PRINT);
     // always print brackets around seq, ignore upper_precedence
     printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1);
 }
 
-void ${CONTAINER}::printtree(ostream & os, unsigned indent) const
+void ${CONTAINER}::printtree(std::ostream & os, unsigned indent) const
 {
     debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT);
 
-    os << string(indent,' ') << "type=" << typeid(*this).name()
-       << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
+    os << std::string(indent,' ') << "type=" << typeid(*this).name()
+       << ", hash=" << hashvalue 
+       << " (0x" << std::hex << hashvalue << std::dec << ")"
        << ", flags=" << flags
-       << ", nops=" << nops() << endl;
+       << ", nops=" << nops() << std::endl;
     for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
         (*cit).printtree(os,indent+delta_indent);
     }
-    os << string(indent+delta_indent,' ') << "=====" << endl;
+    os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
 }
 
 // ${CONTAINER}::info() will be implemented by user elsewhere";
 
-int ${CONTAINER}::nops() const
+unsigned ${CONTAINER}::nops() const
 {
     return seq.size();
 }
@@ -539,9 +502,9 @@ ex ${CONTAINER}::expand(unsigned options) const
 
 // a ${CONTAINER} 'has' an expression if it is this expression itself or a child 'has' it
 
-bool ${CONTAINER}::has(ex const & other) const
+bool ${CONTAINER}::has(const ex & other) const
 {
-    ASSERT(other.bp!=0);
+    GINAC_ASSERT(other.bp!=0);
     if (is_equal(*other.bp)) return true;
     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
         if ((*it).has(other)) return true;
@@ -571,12 +534,12 @@ ex ${CONTAINER}::normal(lst &sym_lst, lst &repl_lst, int level) const
     return n.bp->basic::normal(sym_lst,repl_lst,level);
 }
 
-ex ${CONTAINER}::diff(symbol const & s) const
+ex ${CONTAINER}::derivative(const symbol & s) const
 {
     return this${CONTAINER}(diffchildren(s));
 }
 
-ex ${CONTAINER}::subs(lst const & ls, lst const & lr) const
+ex ${CONTAINER}::subs(const lst & ls, const lst & lr) const
 {
     ${STLT} * vp=subschildren(ls,lr);
     if (vp==0) {
@@ -587,9 +550,9 @@ ex ${CONTAINER}::subs(lst const & ls, lst const & lr) const
 
 // protected
 
-int ${CONTAINER}::compare_same_type(basic const & other) const
+int ${CONTAINER}::compare_same_type(const basic & other) const
 {
-    ASSERT(is_of_type(other,${CONTAINER}));
+    GINAC_ASSERT(is_of_type(other,${CONTAINER}));
     ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
                                     (const_cast<basic &>(other));
     int cmpval;
@@ -608,9 +571,9 @@ int ${CONTAINER}::compare_same_type(basic const & other) const
     return 1;
 }
 
-bool ${CONTAINER}::is_equal_same_type(basic const & other) const
+bool ${CONTAINER}::is_equal_same_type(const basic & other) const
 {
-    ASSERT(is_of_type(other,${CONTAINER}));
+    GINAC_ASSERT(is_of_type(other,${CONTAINER}));
     ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
                                     (const_cast<basic &>(other));
     if (seq.size()!=o.seq.size()) return false;
@@ -636,7 +599,7 @@ unsigned ${CONTAINER}::return_type(void) const
 
 // public
 
-${CONTAINER} & ${CONTAINER}::append(ex const & b)
+${CONTAINER} & ${CONTAINER}::append(const ex & b)
 {
     ensure_if_modifiable();
     seq.push_back(b);
@@ -647,7 +610,7 @@ ${PREPEND_IMPLEMENTATION}
 
 // protected
 
-void ${CONTAINER}::printseq(ostream & os, char openbracket, char delim,
+void ${CONTAINER}::printseq(std::ostream & os, char openbracket, char delim,
                          char closebracket, unsigned this_precedence,
                          unsigned upper_precedence) const
 {
@@ -695,7 +658,7 @@ bool ${CONTAINER}::is_canonical() const
     for (++it; it!=seq.end(); it_last=it, ++it) {
         if ((*it_last).compare(*it)>0) {
             if ((*it_last).compare(*it)>0) {
-                cout << *it_last << ">" << *it << "\\n";
+                std::cout << *it_last << ">" << *it << "\\n";
                 return 0;
                }
         }
@@ -758,7 +721,7 @@ ${STLT} ${CONTAINER}::normalchildren(int level) const
     return s;
 }
 
-${STLT} ${CONTAINER}::diffchildren(symbol const & y) const
+${STLT} ${CONTAINER}::diffchildren(const symbol & y) const
 {
     ${STLT} s;
     RESERVE(s,seq.size());
@@ -769,7 +732,7 @@ ${STLT} ${CONTAINER}::diffchildren(symbol const & y) const
 }
 
 /* obsolete subschildren
-${STLT} ${CONTAINER}::subschildren(lst const & ls, lst const & lr) const
+${STLT} ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
 {
     ${STLT} s;
     RESERVE(s,seq.size());
@@ -780,7 +743,7 @@ ${STLT} ${CONTAINER}::subschildren(lst const & ls, lst const & lr) const
 }
 */
 
-${STLT} * ${CONTAINER}::subschildren(lst const & ls, lst const & lr) const
+${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
 {
     // returns a NULL pointer if nothing had to be substituted
     // returns a pointer to a newly created epvector otherwise
@@ -789,7 +752,7 @@ ${STLT} * ${CONTAINER}::subschildren(lst const & ls, lst const & lr) const
     ${STLT}::const_iterator last=seq.end();
     ${STLT}::const_iterator cit=seq.begin();
     while (cit!=last) {
-        ex const & subsed_ex=(*cit).subs(ls,lr);
+        const ex & subsed_ex=(*cit).subs(ls,lr);
         if (!are_ex_trivially_equal(*cit,subsed_ex)) {
 
             // something changed, copy seq, subs and return it
@@ -831,7 +794,11 @@ unsigned ${CONTAINER}::precedence=10;
 //////////
 
 const ${CONTAINER} some_${CONTAINER};
-type_info const & typeid_${CONTAINER}=typeid(some_${CONTAINER});
+const type_info & typeid_${CONTAINER}=typeid(some_${CONTAINER});
+
+#ifndef NO_NAMESPACE_GINAC
+} // namespace GiNaC
+#endif // ndef NO_NAMESPACE_GINAC
 
 END_OF_IMPLEMENTATION