]> www.ginac.de Git - ginac.git/commitdiff
Use C++11 range-based foor loops and auto, where possible.
authorRichard Kreckel <kreckel@ginac.de>
Tue, 3 Nov 2015 13:15:57 +0000 (14:15 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Tue, 3 Nov 2015 15:41:11 +0000 (16:41 +0100)
25 files changed:
ginac/add.cpp
ginac/basic.cpp
ginac/clifford.cpp
ginac/color.cpp
ginac/container.h
ginac/ex.cpp
ginac/excompiler.cpp
ginac/expairseq.cpp
ginac/factor.cpp
ginac/function.cppy
ginac/indexed.cpp
ginac/matrix.cpp
ginac/mul.cpp
ginac/ncmul.cpp
ginac/normal.cpp
ginac/numeric.cpp
ginac/parser/default_reader.cpp
ginac/polynomial/collect_vargs.cpp
ginac/polynomial/collect_vargs.h
ginac/polynomial/optimal_vars_finder.cpp
ginac/power.cpp
ginac/pseries.cpp
ginac/symbol.cpp
ginac/symmetry.cpp
ginsh/ginsh_parser.ypp

index 36bb2011013efee1abbe28fbc3ea38433dc1791d..74c8d815ca1a6fe0fd197138a86b18c0f8ab8232 100644 (file)
@@ -120,9 +120,8 @@ void add::print_add(const print_context & c, const char *openbrace, const char *
        }
 
        // Then proceed with the remaining factors
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               coeff = ex_to<numeric>(it->coeff);
+       for (auto & it : seq) {
+               coeff = ex_to<numeric>(it.coeff);
                if (!first) {
                        if (coeff.csgn() == -1) c.s << '-'; else c.s << '+';
                } else {
@@ -144,8 +143,7 @@ void add::print_add(const print_context & c, const char *openbrace, const char *
                        }
                        c.s << mul_sym;
                }
-               it->rest.print(c, precedence());
-               ++it;
+               it.rest.print(c, precedence());
        }
 
        if (precedence() <= level)
@@ -168,30 +166,28 @@ void add::do_print_csrc(const print_csrc & c, unsigned level) const
                c.s << "(";
        
        // Print arguments, separated by "+" or "-"
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
        char separator = ' ';
-       while (it != itend) {
+       for (auto & it : seq) {
                
                // If the coefficient is negative, separator is "-"
-               if (it->coeff.is_equal(_ex_1) || 
-                       ex_to<numeric>(it->coeff).numer().is_equal(*_num_1_p))
+               if (it.coeff.is_equal(_ex_1) ||
+                       ex_to<numeric>(it.coeff).numer().is_equal(*_num_1_p))
                        separator = '-';
                c.s << separator;
-               if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1)) {
-                       it->rest.print(c, precedence());
-               } else if (ex_to<numeric>(it->coeff).numer().is_equal(*_num1_p) ||
-                                ex_to<numeric>(it->coeff).numer().is_equal(*_num_1_p))
+               if (it.coeff.is_equal(_ex1) || it.coeff.is_equal(_ex_1)) {
+                       it.rest.print(c, precedence());
+               } else if (ex_to<numeric>(it.coeff).numer().is_equal(*_num1_p) ||
+                                ex_to<numeric>(it.coeff).numer().is_equal(*_num_1_p))
                {
-                       it->rest.print(c, precedence());
+                       it.rest.print(c, precedence());
                        c.s << '/';
-                       ex_to<numeric>(it->coeff).denom().print(c, precedence());
+                       ex_to<numeric>(it.coeff).denom().print(c, precedence());
                } else {
-                       it->coeff.print(c, precedence());
+                       it.coeff.print(c, precedence());
                        c.s << '*';
-                       it->rest.print(c, precedence());
+                       it.rest.print(c, precedence());
                }
                
-               ++it;
                separator = '+';
        }
        
@@ -236,11 +232,9 @@ bool add::info(unsigned inf) const
                case info_flags::even:
                case info_flags::crational_polynomial:
                case info_flags::rational_function: {
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               if (!(recombine_pair_to_ex(*i).info(inf)))
+                       for (auto & i : seq) {
+                               if (!(recombine_pair_to_ex(i).info(inf)))
                                        return false;
-                               ++i;
                        }
                        if (overall_coeff.is_zero() && (inf == info_flags::positive || inf == info_flags::posint))
                                return true;
@@ -261,8 +255,8 @@ bool add::info(unsigned inf) const
 
 bool add::is_polynomial(const ex & var) const
 {
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
-               if (!(i->rest).is_polynomial(var)) {
+       for (auto & i : seq) {
+               if (!i.rest.is_polynomial(var)) {
                        return false;
                }
        }
@@ -276,12 +270,10 @@ int add::degree(const ex & s) const
                deg = 0;
        
        // Find maximum of degrees of individual terms
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               int cur_deg = i->rest.degree(s);
+       for (auto & i : seq) {
+               int cur_deg = i.rest.degree(s);
                if (cur_deg > deg)
                        deg = cur_deg;
-               ++i;
        }
        return deg;
 }
@@ -293,12 +285,10 @@ int add::ldegree(const ex & s) const
                deg = 0;
        
        // Find minimum of degrees of individual terms
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               int cur_deg = i->rest.ldegree(s);
+       for (auto & i : seq) {
+               int cur_deg = i.rest.ldegree(s);
                if (cur_deg < deg)
                        deg = cur_deg;
-               ++i;
        }
        return deg;
 }
@@ -312,21 +302,19 @@ ex add::coeff(const ex & s, int n) const
        bool nonscalar = false;
 
        // Calculate sum of coefficients in each term
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               ex restcoeff = i->rest.coeff(s, n);
+       for (auto & i : seq) {
+               ex restcoeff = i.rest.coeff(s, n);
                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 ? std::move(coeffseq_cliff) : std::move(coeffseq),
@@ -350,10 +338,8 @@ ex add::eval(int level) const
        }
 
 #ifdef DO_GINAC_ASSERT
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               GINAC_ASSERT(!is_exactly_a<add>(i->rest));
-               ++i;
+       for (auto & i : seq) {
+               GINAC_ASSERT(!is_exactly_a<add>(i.rest));
        }
 #endif // def DO_GINAC_ASSERT
        
@@ -376,25 +362,20 @@ ex add::eval(int level) const
        
        // if any terms in the sum still are purely numeric, then they are more
        // appropriately collected into the overall coefficient
-       epvector::const_iterator last = seq.end();
-       epvector::const_iterator j = seq.begin();
        int terms_to_collect = 0;
-       while (j != last) {
-               if (unlikely(is_a<numeric>(j->rest)))
+       for (auto & it : seq) {
+               if (unlikely(is_a<numeric>(it.rest)))
                        ++terms_to_collect;
-               ++j;
        }
        if (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));
+               for (auto & it : seq) {
+                       if (unlikely(is_a<numeric>(it.rest)))
+                               oc = oc.mul(ex_to<numeric>(it.rest)).mul(ex_to<numeric>(it.coeff));
                        else
-                               s.push_back(*j);
-                       ++j;
+                               s.push_back(it);
                }
                return (new add(std::move(s), ex_to<numeric>(overall_coeff).add_dyn(oc)))
                        ->setflag(status_flags::dynallocated);
@@ -414,9 +395,8 @@ ex add::evalm() const
        bool first_term = true;
        matrix sum;
 
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               const ex &m = recombine_pair_to_ex(*it).evalm();
+       for (auto & it : seq) {
+               const ex &m = recombine_pair_to_ex(it).evalm();
                s.push_back(split_ex_to_pair(m));
                if (is_a<matrix>(m)) {
                        if (first_term) {
@@ -426,7 +406,6 @@ ex add::evalm() const
                                sum = sum.add(ex_to<matrix>(m));
                } else
                        all_matrices = false;
-               ++it;
        }
 
        if (all_matrices)
@@ -437,7 +416,7 @@ ex add::evalm() const
 
 ex add::conjugate() const
 {
-       exvector *v = 0;
+       std::unique_ptr<exvector> v(nullptr);
        for (size_t i=0; i<nops(); ++i) {
                if (v) {
                        v->push_back(op(i).conjugate());
@@ -447,16 +426,14 @@ ex add::conjugate() const
                ex ccterm = term.conjugate();
                if (are_ex_trivially_equal(term, ccterm))
                        continue;
-               v = new exvector;
+               v.reset(new exvector);
                v->reserve(nops());
                for (size_t j=0; j<i; ++j)
                        v->push_back(op(j));
                v->push_back(ccterm);
        }
        if (v) {
-               ex result = add(*v);
-               delete v;
-               return result;
+               return add(std::move(*v));
        }
        return *this;
 }
@@ -465,17 +442,17 @@ ex add::real_part() const
 {
        epvector v;
        v.reserve(seq.size());
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
-               if ((i->coeff).info(info_flags::real)) {
-                       ex rp = (i->rest).real_part();
+       for (auto & it : seq)
+               if (it.coeff.info(info_flags::real)) {
+                       ex rp = it.rest.real_part();
                        if (!rp.is_zero())
-                               v.push_back(expair(rp, i->coeff));
+                               v.push_back(expair(rp, it.coeff));
                } else {
-                       ex rp=recombine_pair_to_ex(*i).real_part();
+                       ex rp = recombine_pair_to_ex(it).real_part();
                        if (!rp.is_zero())
                                v.push_back(split_ex_to_pair(rp));
                }
-       return (new add(v, overall_coeff.real_part()))
+       return (new add(std::move(v), overall_coeff.real_part()))
                -> setflag(status_flags::dynallocated);
 }
 
@@ -483,17 +460,17 @@ ex add::imag_part() const
 {
        epvector v;
        v.reserve(seq.size());
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
-               if ((i->coeff).info(info_flags::real)) {
-                       ex ip = (i->rest).imag_part();
+       for (auto & it : seq)
+               if (it.coeff.info(info_flags::real)) {
+                       ex ip = it.rest.imag_part();
                        if (!ip.is_zero())
-                               v.push_back(expair(ip, i->coeff));
+                               v.push_back(expair(ip, it.coeff));
                } else {
-                       ex ip=recombine_pair_to_ex(*i).imag_part();
+                       ex ip = recombine_pair_to_ex(it).imag_part();
                        if (!ip.is_zero())
                                v.push_back(split_ex_to_pair(ip));
                }
-       return (new add(v, overall_coeff.imag_part()))
+       return (new add(std::move(v), overall_coeff.imag_part()))
                -> setflag(status_flags::dynallocated);
 }
 
@@ -517,11 +494,9 @@ ex add::derivative(const symbol & y) const
        // 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));
-               ++i;
-       }
+       for (auto & it : seq)
+               s.push_back(combine_ex_with_coeff_to_pair(it.rest.diff(y), it.coeff));
+
        return (new add(std::move(s), _ex0))->setflag(status_flags::dynallocated);
 }
 
index 563dd7d5b6455fe9453885111bb0aac7a4259ed9..59cd08f3b230fd045056c8cdefa003b797999cca 100644 (file)
@@ -366,13 +366,13 @@ ex basic::collect(const ex & s, bool distributed) const
 
                        exmap cmap;
                        cmap[_ex1] = _ex0;
-                       for (const_iterator xi=x.begin(); xi!=x.end(); ++xi) {
+                       for (const auto & xi : x) {
                                ex key = _ex1;
-                               ex pre_coeff = *xi;
-                               for (lst::const_iterator li=l.begin(); li!=l.end(); ++li) {
-                                       int cexp = pre_coeff.degree(*li);
-                                       pre_coeff = pre_coeff.coeff(*li, cexp);
-                                       key *= pow(*li, cexp);
+                               ex pre_coeff = xi;
+                               for (auto & li : l) {
+                                       int cexp = pre_coeff.degree(li);
+                                       pre_coeff = pre_coeff.coeff(li, cexp);
+                                       key *= pow(li, cexp);
                                }
                                exmap::iterator ci = cmap.find(key);
                                if (ci != cmap.end())
@@ -382,8 +382,8 @@ ex basic::collect(const ex & s, bool distributed) const
                        }
 
                        exvector resv;
-                       for (exmap::const_iterator mi=cmap.begin(); mi != cmap.end(); ++mi)
-                               resv.push_back((mi->first)*(mi->second));
+                       for (auto & mi : cmap)
+                               resv.push_back((mi.first)*(mi.second));
                        return (new add(resv))->setflag(status_flags::dynallocated);
 
                } else {
@@ -548,9 +548,9 @@ bool basic::match(const ex & pattern, exmap& repl_lst) const
                // Wildcard matches anything, but check whether we already have found
                // a match for that wildcard first (if so, the earlier match must be
                // the same expression)
-               for (exmap::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it) {
-                       if (it->first.is_equal(pattern))
-                               return is_equal(ex_to<basic>(it->second));
+               for (auto & it : repl_lst) {
+                       if (it.first.is_equal(pattern))
+                               return is_equal(ex_to<basic>(it.second));
                }
                repl_lst[pattern] = *this;
                return true;
@@ -593,19 +593,16 @@ bool basic::match(const ex & pattern, exmap& repl_lst) const
 /** Helper function for subs(). Does not recurse into subexpressions. */
 ex basic::subs_one_level(const exmap & m, unsigned options) const
 {
-       exmap::const_iterator it;
-
        if (options & subs_options::no_pattern) {
-               ex thisex = *this;
-               it = m.find(thisex);
+               auto it = m.find(*this);
                if (it != m.end())
                        return it->second;
-               return thisex;
+               return *this;
        } else {
-               for (it = m.begin(); it != m.end(); ++it) {
+               for (auto & it : m) {
                        exmap repl_lst;
-                       if (match(ex_to<basic>(it->first), repl_lst))
-                               return it->second.subs(repl_lst, options | subs_options::no_pattern);
+                       if (match(ex_to<basic>(it.first), repl_lst))
+                               return it.second.subs(repl_lst, options | subs_options::no_pattern);
                        // avoid infinite recursion when re-substituting the wildcards
                }
        }
index eb94e0bf462055a5dfc5d77d9b8c31ed4f66a638..16f83196668bd1161cf9f0b3ea52577842bf2682 100644 (file)
@@ -520,11 +520,9 @@ ex clifford::eval_ncmul(const exvector & v) const
        s.reserve(v.size());
 
        // Remove superfluous ONEs
-       exvector::const_iterator cit = v.begin(), citend = v.end();
-       while (cit != citend) {
-               if (!is_a<clifford>(*cit) || !is_a<diracone>(cit->op(0)))
-                       s.push_back(*cit);
-               cit++;
+       for (auto & it : v) {
+               if (!is_a<clifford>(it) || !is_a<diracone>(it.op(0)))
+                       s.push_back(it);
        }
 
        bool something_changed = false;
@@ -1252,15 +1250,13 @@ static ex get_clifford_comp(const ex & e, const ex & c)
                                                
                                                if (ind_vec.size() > 0) {
                                                        found_dummy = true;
-                                                       exvector::const_iterator it = ind_vec.begin(), itend = ind_vec.end();
-                                                       while (it != itend) {
-                                                               ex curridx = *it;
+                                                       for (auto & it : ind_vec) {
+                                                               ex curridx = it;
                                                                ex curridx_toggle = is_a<varidx>(curridx)
                                                                        ? ex_to<varidx>(curridx).toggle_variance()
                                                                        : curridx;
                                                                S = S * e.op(j).subs(lst(curridx == ival,
                                                                        curridx_toggle == ival), subs_options::no_pattern);
-                                                               ++it;
                                                        }
                                                } else
                                                        S = S * e.op(j);
index 09e52517ebb861f1477102566e006c3b4b92854b..1d006e495dc3421df2913e39cfc9d705ec4ddfd1 100644 (file)
@@ -166,11 +166,9 @@ ex color::eval_ncmul(const exvector & v) const
        s.reserve(v.size());
 
        // Remove superfluous ONEs
-       exvector::const_iterator it = v.begin(), itend = v.end();
-       while (it != itend) {
-               if (!is_a<su3one>(it->op(0)))
-                       s.push_back(*it);
-               it++;
+       for (auto & it : v) {
+               if (!is_a<su3one>(it.op(0)))
+                       s.push_back(it);
        }
 
        if (s.empty())
@@ -625,9 +623,9 @@ ex color_trace(const ex & e, const lst & rll)
 {
        // Convert list to set
        std::set<unsigned char> rls;
-       for (lst::const_iterator i = rll.begin(); i != rll.end(); ++i) {
-               if (i->info(info_flags::nonnegint))
-                       rls.insert(ex_to<numeric>(*i).to_int());
+       for (auto & it : rll) {
+               if (it.info(info_flags::nonnegint))
+                       rls.insert(ex_to<numeric>(it).to_int());
        }
 
        return color_trace(e, rls);
index 3c9d560132dcfced847f2397c24ed1c69ce1bd0a..cca5c673780a2e69f20f962c0d482885ed6405fd 100644 (file)
@@ -384,10 +384,8 @@ public:
        void 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;
+               for (auto & i : this->seq) {
+                       n.add_ex("seq", i);
                }
        }
 
index ee6827aad0b144686396f3962253daf3491166b3..290154b4838e863859db143e181ea337e8ef9e75 100644 (file)
@@ -162,8 +162,7 @@ ex ex::subs(const ex & e, unsigned options) const
                // Argument is a list: convert it to a map
                exmap m;
                GINAC_ASSERT(is_a<lst>(e));
-               for (lst::const_iterator it = ex_to<lst>(e).begin(); it != ex_to<lst>(e).end(); ++it) {
-                       ex r = *it;
+               for (auto & r : ex_to<lst>(e)) {
                        if (!r.info(info_flags::relation_equal))
                                throw(std::invalid_argument("basic::subs(ex): argument must be a list of equations"));
                        const ex & s = r.op(0);
@@ -243,8 +242,8 @@ bool ex::is_polynomial(const ex & vars) const
 {
        if (is_a<lst>(vars)) {
                const lst & varlst = ex_to<lst>(vars);
-               for (lst::const_iterator i=varlst.begin(); i!=varlst.end(); ++i)
-                       if (!bp->is_polynomial(*i))
+               for (auto & it : varlst)
+                       if (!bp->is_polynomial(it))
                                return false;
                return true;
        }
index 36cb8ffcf01fe203ef5ddcad686a4c521b81cb72..28c24a4ac9a6986631224508706f3d02a10e682f 100644 (file)
@@ -76,7 +76,7 @@ public:
         */
        ~excompiler()
        {
-               for (std::vector<filedesc>::const_iterator it = filelist.begin(); it != filelist.end(); ++it) {
+               for (auto it = filelist.begin(); it != filelist.end(); ++it) {
                        clean_up(it);
                }
        }
@@ -169,7 +169,7 @@ public:
         */
        void unlink(const std::string filename)
        {
-               for (std::vector<filedesc>::iterator it = filelist.begin(); it != filelist.end();) {
+               for (auto it = filelist.begin(); it != filelist.end();) {
                        if (it->name == filename) {
                                clean_up(it);
                                it = filelist.erase(it);
index 963cd23931b3a503c9edd323e55d55ce99e5bf92..67099f5796395e7d012fb1d4a13484278675e800 100644 (file)
@@ -110,12 +110,12 @@ expairseq::expairseq(epvector && vp, const ex &oc, bool do_index_renaming)
 void expairseq::read_archive(const archive_node &n, lst &sym_lst) 
 {
        inherited::read_archive(n, sym_lst);
-       archive_node::archive_node_cit first = n.find_first("rest");
-       archive_node::archive_node_cit last = n.find_last("coeff");
+       auto first = n.find_first("rest");
+       auto last = n.find_last("coeff");
        ++last;
        seq.reserve((last-first)/2);
 
-       for (archive_node::archive_node_cit loc = first; loc < last;) {
+       for (auto loc = first; loc < last;) {
                ex rest;
                ex coeff;
                n.find_ex_by_loc(loc++, rest, sym_lst);
@@ -132,11 +132,9 @@ void expairseq::read_archive(const archive_node &n, lst &sym_lst)
 void expairseq::archive(archive_node &n) const
 {
        inherited::archive(n);
-       epvector::const_iterator i = seq.begin(), iend = seq.end();
-       while (i != iend) {
-               n.add_ex("rest", i->rest);
-               n.add_ex("coeff", i->coeff);
-               ++i;
+       for (auto & i : seq) {
+               n.add_ex("rest", i.rest);
+               n.add_ex("coeff", i.coeff);
        }
        n.add_ex("overall_coeff", overall_coeff);
 }
@@ -186,8 +184,8 @@ bool expairseq::info(unsigned inf) const
                                return true;
                        else if (flags & status_flags::has_no_indices)
                                return false;
-                       for (epvector::const_iterator i = seq.begin(); i != seq.end(); ++i) {
-                               if (i->rest.info(info_flags::has_indices)) {
+                       for (auto & i : seq) {
+                               if (i.rest.info(info_flags::has_indices)) {
                                        this->setflag(status_flags::has_indices);
                                        this->clearflag(status_flags::has_no_indices);
                                        return true;
@@ -222,11 +220,8 @@ ex expairseq::map(map_function &f) const
        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))));
-               ++cit;
-       }
+       for (auto & it : seq)
+               v.push_back(split_ex_to_pair(f(recombine_pair_to_ex(it))));
 
        if (overall_coeff.is_equal(default_overall_coeff()))
                return thisexpairseq(std::move(v), default_overall_coeff(), true);
@@ -256,9 +251,9 @@ ex expairseq::eval(int level) const
 
 epvector* conjugateepvector(const epvector&epv)
 {
-       epvector *newepv = 0;
-       for (epvector::const_iterator i=epv.begin(); i!=epv.end(); ++i) {
-               if(newepv) {
+       epvector *newepv = nullptr;
+       for (auto i=epv.begin(); i!=epv.end(); ++i) {
+               if (newepv) {
                        newepv->push_back(i->conjugate());
                        continue;
                }
@@ -278,12 +273,10 @@ epvector* conjugateepvector(const epvector&epv)
 
 ex expairseq::conjugate() const
 {
-       epvector* newepv = conjugateepvector(seq);
+       std::unique_ptr<epvector> newepv(conjugateepvector(seq));
        ex x = overall_coeff.conjugate();
        if (newepv) {
-               ex result = thisexpairseq(std::move(*newepv), x);
-               delete newepv;
-               return result;
+               return thisexpairseq(std::move(*newepv), x);
        }
        if (are_ex_trivially_equal(x, overall_coeff)) {
                return *this;
@@ -331,7 +324,7 @@ bool expairseq::match(const ex & pattern, exmap & repl_lst) const
                        ex p = pattern.op(i);
                        if (has_global_wildcard && p.is_equal(global_wildcard))
                                continue;
-                       exvector::iterator it = ops.begin(), itend = ops.end();
+                       auto it = ops.begin(), itend = ops.end();
                        while (it != itend) {
                                if (it->match(p, tmp_repl)) {
                                        ops.erase(it);
@@ -354,9 +347,9 @@ found:              ;
                        for (size_t i=0; i<num; i++)
                                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)) {
+                       for (auto & it : tmp_repl) {
+                               if (it.first.is_equal(global_wildcard)) {
+                                       if (rest.is_equal(it.second)) {
                                                repl_lst = tmp_repl;
                                                return true;
                                        }
@@ -410,12 +403,9 @@ int expairseq::compare_same_type(const basic &other) const
        if (cmpval!=0)
                return cmpval;
        
-       epvector::const_iterator cit1 = seq.begin();
-       epvector::const_iterator cit2 = o.seq.begin();
-       epvector::const_iterator last1 = seq.end();
-       epvector::const_iterator last2 = o.seq.end();
-               
-       for (; (cit1!=last1)&&(cit2!=last2); ++cit1, ++cit2) {
+       auto cit1 = seq.begin(), last1 = seq.end();
+       auto cit2 = o.seq.begin(), last2 = o.seq.end();
+       for (; (cit1!=last1) && (cit2!=last2); ++cit1, ++cit2) {
                cmpval = (*cit1).compare(*cit2);
                if (cmpval!=0) return cmpval;
        }
@@ -438,13 +428,10 @@ bool expairseq::is_equal_same_type(const basic &other) const
        if (!overall_coeff.is_equal(o.overall_coeff))
                return false;
        
-       epvector::const_iterator cit1 = seq.begin();
-       epvector::const_iterator cit2 = o.seq.begin();
-       epvector::const_iterator last1 = seq.end();
-               
-       while (cit1!=last1) {
-               if (!(*cit1).is_equal(*cit2)) return false;
-               ++cit1;
+       auto cit2 = o.seq.begin();
+       for (auto & cit1 : seq) {
+               if (!cit1.is_equal(*cit2))
+                       return false;
                ++cit2;
        }
 
@@ -459,13 +446,10 @@ unsigned expairseq::return_type() const
 unsigned expairseq::calchash() const
 {
        unsigned v = make_hash_seed(typeid(*this));
-       epvector::const_iterator i = seq.begin();
-       const epvector::const_iterator end = seq.end();
-       while (i != end) {
-               v ^= i->rest.gethash();
+       for (auto & i : seq) {
+               v ^= i.rest.gethash();
                v = rotate_left(v);
-               v ^= i->coeff.gethash();
-               ++i;
+               v ^= i.coeff.gethash();
        }
 
        v ^= overall_coeff.gethash();
@@ -527,8 +511,8 @@ void expairseq::printseq(const print_context & c, char delim,
 {
        if (this_precedence <= upper_precedence)
                c.s << "(";
-       epvector::const_iterator it, it_last = seq.end() - 1;
-       for (it=seq.begin(); it!=it_last; ++it) {
+       auto it = seq.begin(), it_last = seq.end() - 1;
+       for (; it!=it_last; ++it) {
                printpair(c, *it, this_precedence);
                c.s << delim;
        }
@@ -689,10 +673,8 @@ void expairseq::construct_from_2_expairseq(const expairseq &s1,
        combine_overall_coeff(s1.overall_coeff);
        combine_overall_coeff(s2.overall_coeff);
 
-       epvector::const_iterator first1 = s1.seq.begin();
-       epvector::const_iterator last1 = s1.seq.end();
-       epvector::const_iterator first2 = s2.seq.begin();
-       epvector::const_iterator last2 = s2.seq.end();
+       auto first1 = s1.seq.begin(), last1 = s1.seq.end();
+       auto first2 = s2.seq.begin(), last2 = s2.seq.end();
 
        seq.reserve(s1.seq.size()+s2.seq.size());
 
@@ -748,8 +730,7 @@ void expairseq::construct_from_expairseq_ex(const expairseq &s,
                return;
        }
        
-       epvector::const_iterator first = s.seq.begin();
-       epvector::const_iterator last = s.seq.end();
+       auto first = s.seq.begin(), last = s.seq.end();
        expair p = split_ex_to_pair(e);
        
        seq.reserve(s.seq.size()+1);
@@ -840,24 +821,20 @@ void expairseq::construct_from_epvector(epvector &&v, bool do_index_renaming)
  *  It cares for associativity as well as for special handling of numerics. */
 void expairseq::make_flat(const exvector &v)
 {
-       exvector::const_iterator cit;
-       
        // count number of operands which are of same expairseq derived type
        // and their cumulative number of operands
        int nexpairseqs = 0;
        int noperands = 0;
        bool do_idx_rename = false;
        
-       cit = v.begin();
-       while (cit!=v.end()) {
-               if (typeid(ex_to<basic>(*cit)) == typeid(*this)) {
+       for (auto & cit : v) {
+               if (typeid(ex_to<basic>(cit)) == typeid(*this)) {
                        ++nexpairseqs;
-                       noperands += ex_to<expairseq>(*cit).seq.size();
+                       noperands += ex_to<expairseq>(cit).seq.size();
                }
                if (is_a<mul>(*this) && (!do_idx_rename) &&
-                               cit->info(info_flags::has_indices))
+                   cit.info(info_flags::has_indices))
                        do_idx_rename = true;
-               ++cit;
        }
        
        // reserve seq and coeffseq which will hold all operands
@@ -865,26 +842,22 @@ void expairseq::make_flat(const exvector &v)
        
        // copy elements and split off numerical part
        make_flat_inserter mf(v, do_idx_rename);
-       cit = v.begin();
-       while (cit!=v.end()) {
-               if (typeid(ex_to<basic>(*cit)) == typeid(*this)) {
-                       ex newfactor = mf.handle_factor(*cit, _ex1);
+       for (auto & cit : v) {
+               if (typeid(ex_to<basic>(cit)) == typeid(*this)) {
+                       ex newfactor = mf.handle_factor(cit, _ex1);
                        const expairseq &subseqref = ex_to<expairseq>(newfactor);
                        combine_overall_coeff(subseqref.overall_coeff);
-                       epvector::const_iterator cit_s = subseqref.seq.begin();
-                       while (cit_s!=subseqref.seq.end()) {
-                               seq.push_back(*cit_s);
-                               ++cit_s;
+                       for (auto & cit_s : subseqref.seq) {
+                               seq.push_back(cit_s);
                        }
                } else {
-                       if (is_exactly_a<numeric>(*cit))
-                               combine_overall_coeff(*cit);
+                       if (is_exactly_a<numeric>(cit))
+                               combine_overall_coeff(cit);
                        else {
-                               ex newfactor = mf.handle_factor(*cit, _ex1);
+                               ex newfactor = mf.handle_factor(cit, _ex1);
                                seq.push_back(split_ex_to_pair(newfactor));
                        }
                }
-               ++cit;
        }
 }
 
@@ -892,24 +865,20 @@ void expairseq::make_flat(const exvector &v)
  *  It cares for associativity as well as for special handling of numerics. */
 void expairseq::make_flat(const epvector &v, bool do_index_renaming)
 {
-       epvector::const_iterator cit;
-       
        // count number of operands which are of same expairseq derived type
        // and their cumulative number of operands
        int nexpairseqs = 0;
        int noperands = 0;
        bool really_need_rename_inds = false;
        
-       cit = v.begin();
-       while (cit!=v.end()) {
-               if (typeid(ex_to<basic>(cit->rest)) == typeid(*this)) {
+       for (auto & cit : v) {
+               if (typeid(ex_to<basic>(cit.rest)) == typeid(*this)) {
                        ++nexpairseqs;
-                       noperands += ex_to<expairseq>(cit->rest).seq.size();
+                       noperands += ex_to<expairseq>(cit.rest).seq.size();
                }
                if ((!really_need_rename_inds) && is_a<mul>(*this) &&
-                               cit->rest.info(info_flags::has_indices))
+                   cit.rest.info(info_flags::has_indices))
                        really_need_rename_inds = true;
-               ++cit;
        }
        do_index_renaming = do_index_renaming && really_need_rename_inds;
        
@@ -918,33 +887,29 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
        make_flat_inserter mf(v, do_index_renaming);
        
        // copy elements and split off numerical part
-       cit = v.begin();
-       while (cit!=v.end()) {
-               if ((typeid(ex_to<basic>(cit->rest)) == typeid(*this)) &&
-                   this->can_make_flat(*cit)) {
-                       ex newrest = mf.handle_factor(cit->rest, cit->coeff);
+       for (auto & cit : v) {
+               if (typeid(ex_to<basic>(cit.rest)) == typeid(*this) &&
+                   this->can_make_flat(cit)) {
+                       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));
-                       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))));
-                               ++cit_s;
+                                             ex_to<numeric>(cit.coeff));
+                       for (auto & cit_s : subseqref.seq) {
+                               seq.push_back(expair(cit_s.rest,
+                                                    ex_to<numeric>(cit_s.coeff).mul_dyn(ex_to<numeric>(cit.coeff))));
                        }
                } else {
-                       if (cit->is_canonical_numeric())
-                               combine_overall_coeff(mf.handle_factor(cit->rest, _ex1));
+                       if (cit.is_canonical_numeric())
+                               combine_overall_coeff(mf.handle_factor(cit.rest, _ex1));
                        else {
-                               ex rest = cit->rest;
-                               ex newrest = mf.handle_factor(rest, cit->coeff);
+                               ex rest = cit.rest;
+                               ex newrest = mf.handle_factor(rest, cit.coeff);
                                if (are_ex_trivially_equal(newrest, rest))
-                                       seq.push_back(*cit);
+                                       seq.push_back(cit);
                                else
-                                       seq.push_back(expair(newrest, cit->coeff));
+                                       seq.push_back(expair(newrest, cit.coeff));
                        }
                }
-               ++cit;
        }
 }
 
@@ -965,10 +930,10 @@ void expairseq::combine_same_terms_sorted_seq()
 
        bool needs_further_processing = false;
 
-       epvector::iterator itin1 = seq.begin();
-       epvector::iterator itin2 = itin1+1;
-       epvector::iterator itout = itin1;
-       epvector::iterator last = seq.end();
+       auto itin1 = seq.begin();
+       auto itin2 = itin1 + 1;
+       auto itout = itin1;
+       auto last = seq.end();
        // must_copy will be set to true the first time some combination is 
        // possible from then on the sequence has changed and must be compacted
        bool must_copy = false;
@@ -1011,8 +976,8 @@ bool expairseq::is_canonical() const
        if (seq.size() <= 1)
                return 1;
        
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       epvector::const_iterator it_last = it;
+       auto it = seq.begin(), itend = seq.end();
+       auto it_last = it;
        for (++it; it!=itend; it_last=it, ++it) {
                if (!(it_last->is_less(*it) || it_last->is_equal(*it))) {
                        if (!is_exactly_a<numeric>(it_last->rest) ||
@@ -1045,8 +1010,7 @@ bool expairseq::is_canonical() const
  *    had to be changed. */
 epvector expairseq::expandchildren(unsigned options) const
 {
-       const epvector::const_iterator last = seq.end();
-       epvector::const_iterator cit = seq.begin();
+       auto cit = seq.begin(), last = seq.end();
        while (cit!=last) {
                const ex &expanded_ex = cit->rest.expand(options);
                if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
@@ -1056,7 +1020,7 @@ epvector expairseq::expandchildren(unsigned options) const
                        s.reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
-                       epvector::const_iterator cit2 = seq.begin();
+                       auto cit2 = seq.begin();
                        while (cit2!=cit) {
                                s.push_back(*cit2);
                                ++cit2;
@@ -1096,8 +1060,7 @@ epvector expairseq::evalchildren(int level) const
                throw(std::runtime_error("max recursion level reached"));
        
        --level;
-       epvector::const_iterator last = seq.end();
-       epvector::const_iterator cit = seq.begin();
+       auto cit = seq.begin(), last = seq.end();
        while (cit!=last) {
                const ex evaled_ex = cit->rest.eval(level);
                if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
@@ -1107,7 +1070,7 @@ epvector expairseq::evalchildren(int level) const
                        s.reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
-                       epvector::const_iterator cit2=seq.begin();
+                       auto cit2 = seq.begin();
                        while (cit2!=cit) {
                                s.push_back(*cit2);
                                ++cit2;
@@ -1145,8 +1108,8 @@ epvector expairseq::subschildren(const exmap & m, unsigned options) const
        if (!(options & (subs_options::pattern_is_product | subs_options::pattern_is_not_product))) {
 
                // Search the list of substitutions and cache our findings
-               for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
-                       if (is_exactly_a<mul>(it->first) || is_exactly_a<power>(it->first)) {
+               for (auto & it : m) {
+                       if (is_exactly_a<mul>(it.first) || is_exactly_a<power>(it.first)) {
                                options |= subs_options::pattern_is_product;
                                break;
                        }
@@ -1158,7 +1121,7 @@ epvector expairseq::subschildren(const exmap & m, unsigned options) const
        if (options & subs_options::pattern_is_product) {
 
                // Substitute in the recombined pairs
-               epvector::const_iterator cit = seq.begin(), last = seq.end();
+               auto cit = seq.begin(), last = seq.end();
                while (cit != last) {
 
                        const ex &orig_ex = recombine_pair_to_ex(*cit);
@@ -1190,7 +1153,7 @@ epvector expairseq::subschildren(const exmap & m, unsigned options) const
        } else {
 
                // Substitute only in the "rest" part of the pairs
-               epvector::const_iterator cit = seq.begin(), last = seq.end();
+               auto cit = seq.begin(), last = seq.end();
                while (cit != last) {
 
                        const ex &subsed_ex = cit->rest.subs(m, options);
index cb5be83624f297ab6aaee664acf5e28f0b12894a..5ff3cd38c73074cf89f5ae64459c101f749cfb4c 100644 (file)
@@ -86,15 +86,16 @@ namespace GiNaC {
 #define DCOUT2(str,var) cout << #str << ": " << var << endl
 ostream& operator<<(ostream& o, const vector<int>& v)
 {
-       vector<int>::const_iterator i = v.begin(), end = v.end();
+       auto i = v.begin(), end = v.end();
        while ( i != end ) {
-               o << *i++ << " ";
+               o << *i << " ";
+               ++i;
        }
        return o;
 }
 static ostream& operator<<(ostream& o, const vector<cl_I>& v)
 {
-       vector<cl_I>::const_iterator i = v.begin(), end = v.end();
+       auto i = v.begin(), end = v.end();
        while ( i != end ) {
                o << *i << "[" << i-v.begin() << "]" << " ";
                ++i;
@@ -103,7 +104,7 @@ static ostream& operator<<(ostream& o, const vector<cl_I>& v)
 }
 static ostream& operator<<(ostream& o, const vector<cl_MI>& v)
 {
-       vector<cl_MI>::const_iterator i = v.begin(), end = v.end();
+       auto i = v.begin(), end = v.end();
        while ( i != end ) {
                o << *i << "[" << i-v.begin() << "]" << " ";
                ++i;
@@ -119,7 +120,7 @@ ostream& operator<<(ostream& o, const vector<numeric>& v)
 }
 ostream& operator<<(ostream& o, const vector< vector<cl_MI> >& v)
 {
-       vector< vector<cl_MI> >::const_iterator i = v.begin(), end = v.end();
+       auto i = v.begin(), end = v.end();
        while ( i != end ) {
                o << i-v.begin() << ": " << *i << endl;
                ++i;
@@ -498,11 +499,10 @@ static void reduce_coeff(umodpoly& a, const cl_I& x)
        if ( a.empty() ) return;
 
        cl_modint_ring R = a[0].ring();
-       umodpoly::iterator i = a.begin(), end = a.end();
-       for ( ; i!=end; ++i ) {
+       for (auto & i : a) {
                // cln cannot perform this division in the modular field
-               cl_I c = R->retract(*i);
-               *i = cl_MI(R, the<cl_I>(c / x));
+               cl_I c = R->retract(i);
+               i = cl_MI(R, the<cl_I>(c / x));
        }
 }
 
@@ -940,15 +940,13 @@ static void berlekamp(const umodpoly& a, upvec& upv)
                                }
                                factors.push_back(g);
                                size = 0;
-                               list<umodpoly>::const_iterator i = factors.begin(), end = factors.end();
-                               while ( i != end ) {
-                                       if ( degree(*i) ) ++size; 
-                                       ++i;
+                               for (auto & i : factors) {
+                                       if (degree(i))
+                                               ++size;
                                }
                                if ( size == k ) {
-                                       list<umodpoly>::const_iterator i = factors.begin(), end = factors.end();
-                                       while ( i != end ) {
-                                               upv.push_back(*i++);
+                                       for (auto & i : factors) {
+                                               upv.push_back(i);
                                        }
                                        return;
                                }
@@ -1172,15 +1170,13 @@ static void exteuclid(const umodpoly& a, const umodpoly& b, umodpoly& s, umodpol
                d2 = r2;
        }
        cl_MI fac = recip(lcoeff(a) * lcoeff(c));
-       umodpoly::iterator i = s.begin(), end = s.end();
-       for ( ; i!=end; ++i ) {
-               *i = *i * fac;
+       for (auto & i : s) {
+               i = i * fac;
        }
        canonicalize(s);
        fac = recip(lcoeff(b) * lcoeff(c));
-       i = t.begin(), end = t.end();
-       for ( ; i!=end; ++i ) {
-               *i = *i * fac;
+       for (auto & i : t) {
+               i = i * fac;
        }
        canonicalize(t);
 }
@@ -1332,7 +1328,6 @@ static unsigned int next_prime(unsigned int p)
        if ( primes.size() == 0 ) {
                primes.push_back(3); primes.push_back(5); primes.push_back(7);
        }
-       vector<unsigned int>::const_iterator it = primes.begin();
        if ( p >= primes.back() ) {
                unsigned int candidate = primes.back() + 2;
                while ( true ) {
@@ -1347,10 +1342,9 @@ static unsigned int next_prime(unsigned int p)
                }
                return candidate;
        }
-       vector<unsigned int>::const_iterator end = primes.end();
-       for ( ; it!=end; ++it ) {
-               if ( *it > p ) {
-                       return *it;
+       for (auto & it : primes) {
+               if ( it > p ) {
+                       return it;
                }
        }
        throw logic_error("next_prime: should not reach this point!");
@@ -1603,7 +1597,7 @@ static ex factor_univariate(const ex& poly, const ex& x, unsigned int& prime)
                                }
                                else {
                                        upvec newfactors1(part.size_left()), newfactors2(part.size_right());
-                                       upvec::iterator i1 = newfactors1.begin(), i2 = newfactors2.begin();
+                                       auto i1 = newfactors1.begin(), i2 = newfactors2.begin();
                                        for ( size_t i=0; i<n; ++i ) {
                                                if ( part[i] ) {
                                                        *i2++ = tocheck.top().factors[i];
@@ -1719,9 +1713,8 @@ static void change_modulus(const cl_modint_ring& R, umodpoly& a)
 {
        if ( a.empty() ) return;
        cl_modint_ring oldR = a[0].ring();
-       umodpoly::iterator i = a.begin(), end = a.end();
-       for ( ; i!=end; ++i ) {
-               *i = R->canonhom(oldR->retract(*i));
+       for (auto & i : a) {
+               i = R->canonhom(oldR->retract(i));
        }
        canonicalize(a);
 }
@@ -2556,9 +2549,8 @@ ex factor(const ex& poly, unsigned options)
                return poly;
        }
        lst syms;
-       exset::const_iterator i=findsymbols.syms.begin(), end=findsymbols.syms.end();
-       for ( ; i!=end; ++i ) {
-               syms.append(*i);
+       for (auto & i : findsymbols.syms ) {
+               syms.append(i);
        }
 
        // make poly square free
index 45f33ec16b53ba32d6e020067bf708f0ba262ced..4f0c6cfc33535c5040a0eb6006866bf70dd58e41 100644 (file)
@@ -264,13 +264,12 @@ void function::read_archive(const archive_node& n, lst& sym_lst)
        std::string s;
        if (n.find_string("name", s)) {
                unsigned int ser = 0;
-               std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
-               while (i != iend) {
-                       if (s == i->name) {
+               for (auto & it : registered_functions()) {
+                       if (s == it.name) {
                                serial = ser;
                                return;
                        }
-                       ++i; ++ser;
+                       ++ser;
                }
                throw (std::runtime_error("unknown function '" + s + "' in archive"));
        } else
@@ -431,10 +430,8 @@ ex function::evalf(int level) const
        else {
                eseq.reserve(seq.size());
                --level;
-               exvector::const_iterator it = seq.begin(), itend = seq.end();
-               while (it != itend) {
-                       eseq.push_back(it->evalf(level));
-                       ++it;
+               for (auto & it : seq) {
+                       eseq.push_back(it.evalf(level));
                }
        }
 
@@ -875,12 +872,10 @@ unsigned function::register_new(function_options const & opt)
  *  Throws exception if function was not found. */
 unsigned function::find_function(const std::string &name, unsigned nparams)
 {
-       std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
        unsigned serial = 0;
-       while (i != end) {
-               if (i->get_name() == name && i->get_nparams() == nparams)
+       for (auto & it : function::registered_functions()) {
+               if (it.get_name() == name && it.get_nparams() == nparams)
                        return serial;
-               ++i;
                ++serial;
        }
        throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
index f209829da3abe8569369dc3a7c56ded3e80b0f0d..5e63d8944db9d7156e68f3d108af3d7f75869e13 100644 (file)
@@ -166,7 +166,7 @@ void indexed::printindices(const print_context & c, unsigned level) const
 {
        if (seq.size() > 1) {
 
-               exvector::const_iterator it=seq.begin() + 1, itend = seq.end();
+               auto it = seq.begin() + 1, itend = seq.end();
 
                if (is_a<print_latex>(c)) {
 
@@ -377,7 +377,7 @@ ex indexed::expand(unsigned options) const
 void indexed::validate() const
 {
        GINAC_ASSERT(seq.size() > 0);
-       exvector::const_iterator it = seq.begin() + 1, itend = seq.end();
+       auto it = seq.begin() + 1, itend = seq.end();
        while (it != itend) {
                if (!is_a<idx>(*it))
                        throw(std::invalid_argument("indices of indexed object must be of type idx"));
@@ -454,7 +454,7 @@ exvector indexed::get_dummy_indices(const indexed & other) const
 
 bool indexed::has_dummy_index_for(const ex & i) const
 {
-       exvector::const_iterator it = seq.begin() + 1, itend = seq.end();
+       auto it = seq.begin() + 1, itend = seq.end();
        while (it != itend) {
                if (is_dummy_pair(*it, i))
                        return true;
@@ -532,8 +532,8 @@ exvector integral::get_free_indices() const
 template<class T> size_t number_of_type(const exvector&v)
 {
        size_t number = 0;
-       for(exvector::const_iterator i=v.begin(); i!=v.end(); ++i)
-               if(is_exactly_a<T>(*i))
+       for (auto & it : v)
+               if (is_exactly_a<T>(it))
                        ++number;
        return number;
 }
@@ -561,7 +561,7 @@ template<class T> static ex rename_dummy_indices(const ex & e, exvector & global
                // to the global set
                size_t old_global_size = global_size;
                int remaining = local_size - global_size;
-               exvector::const_iterator it = local_dummy_indices.begin(), itend = local_dummy_indices.end();
+               auto it = local_dummy_indices.begin(), itend = local_dummy_indices.end();
                while (it != itend && remaining > 0) {
                        if (is_exactly_a<T>(*it) && find_if(global_dummy_indices.begin(), global_dummy_indices.end(), bind2nd(idx_is_equal_ignore_dim(), *it)) == global_dummy_indices.end()) {
                                global_dummy_indices.push_back(*it);
@@ -635,8 +635,7 @@ bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector
                for (size_t j=i+1; j<e.nops(); ++j) {
                        if (is_dummy_pair(e.op(i), e.op(j))) {
                                local_var_dummies.push_back(e.op(i));
-                               for (exvector::iterator k = variant_dummy_indices.begin();
-                                               k!=variant_dummy_indices.end(); ++k) {
+                               for (auto k = variant_dummy_indices.begin(); k!=variant_dummy_indices.end(); ++k) {
                                        if (e.op(i).op(0) == k->op(0)) {
                                                variant_dummy_indices.erase(k);
                                                break;
@@ -678,8 +677,7 @@ bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector
 
        // If a dummy index is encountered for the first time in the
        // product, pull it up, otherwise, pull it down
-       for (exvector::iterator it2 = seq.begin()+1, it2end = seq.end();
-                       it2 != it2end; ++it2) {
+       for (auto it2 = seq.begin()+1, it2end = seq.end(); it2 != it2end; ++it2) {
                if (!is_exactly_a<varidx>(*it2))
                        continue;
 
@@ -771,9 +769,9 @@ static void product_to_exvector(const ex & e, exvector & v, bool & non_commutati
 template<class T> ex idx_symmetrization(const ex& r,const exvector& local_dummy_indices)
 {      exvector dummy_syms;
        dummy_syms.reserve(r.nops());
-       for (exvector::const_iterator it = local_dummy_indices.begin(); it != local_dummy_indices.end(); ++it)
-                       if(is_exactly_a<T>(*it))
-                               dummy_syms.push_back(it->op(0));
+       for (auto & it : local_dummy_indices)
+                       if(is_exactly_a<T>(it))
+                               dummy_syms.push_back(it.op(0));
        if(dummy_syms.size() < 2)
                return r;
        ex q=symmetrize(r, dummy_syms);
@@ -1131,9 +1129,9 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi
                        const ex & term = sum.op(i);
                        exvector dummy_indices_of_term;
                        dummy_indices_of_term.reserve(dummy_indices.size());
-                       for(exvector::iterator i=dummy_indices.begin(); i!=dummy_indices.end(); ++i)
-                               if(hasindex(term,i->op(0)))
-                                       dummy_indices_of_term.push_back(*i);
+                       for (auto & i : dummy_indices)
+                               if (hasindex(term,i.op(0)))
+                                       dummy_indices_of_term.push_back(i);
                        ex term_symm = idx_symmetrization<idx>(term, dummy_indices_of_term);
                        term_symm = idx_symmetrization<varidx>(term_symm, dummy_indices_of_term);
                        term_symm = idx_symmetrization<spinidx>(term_symm, dummy_indices_of_term);
@@ -1149,7 +1147,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi
                std::vector<terminfo> terms_pass2;
                for (std::vector<terminfo>::const_iterator i=terms.begin(); i!=terms.end(); ) {
                        size_t num = 1;
-                       std::vector<terminfo>::const_iterator j = i + 1;
+                       auto j = i + 1;
                        while (j != terms.end() && j->symm == i->symm) {
                                num++;
                                j++;
@@ -1164,13 +1162,13 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi
 
                // Chop the symmetrized terms into subterms
                std::vector<symminfo> sy;
-               for (std::vector<terminfo>::const_iterator i=terms_pass2.begin(); i!=terms_pass2.end(); ++i) {
-                       if (is_exactly_a<add>(i->symm)) {
-                               size_t num = i->symm.nops();
+               for (auto & i : terms_pass2) {
+                       if (is_exactly_a<add>(i.symm)) {
+                               size_t num = i.symm.nops();
                                for (size_t j=0; j<num; j++)
-                                       sy.push_back(symminfo(i->symm.op(j), i->orig, num));
+                                       sy.push_back(symminfo(i.symm.op(j), i.orig, num));
                        } else
-                               sy.push_back(symminfo(i->symm, i->orig, 1));
+                               sy.push_back(symminfo(i.symm, i.orig, 1));
                }
 
                // Sort by symmetrized subterms
@@ -1179,10 +1177,10 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi
                // Combine equal symmetrized subterms
                std::vector<symminfo> sy_pass2;
                exvector result;
-               for (std::vector<symminfo>::const_iterator i=sy.begin(); i!=sy.end(); ) {
+               for (auto i=sy.begin(); i!=sy.end(); ) {
 
                        // Combine equal terms
-                       std::vector<symminfo>::const_iterator j = i + 1;
+                       auto j = i + 1;
                        if (j != sy.end() && j->symmterm == i->symmterm) {
 
                                // More than one term, collect the coefficients
@@ -1215,7 +1213,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi
 
                                // How many symmetrized terms of this original term are left?
                                size_t num = 1;
-                               std::vector<symminfo>::const_iterator j = i + 1;
+                               auto j = i + 1;
                                while (j != sy_pass2.end() && j->orig == i->orig) {
                                        num++;
                                        j++;
@@ -1367,9 +1365,9 @@ void scalar_products::add(const ex & v1, const ex & v2, const ex & dim, const ex
 void scalar_products::add_vectors(const lst & l, const ex & dim)
 {
        // Add all possible pairs of products
-       for (lst::const_iterator it1 = l.begin(); it1 != l.end(); ++it1)
-               for (lst::const_iterator it2 = l.begin(); it2 != l.end(); ++it2)
-                       add(*it1, *it2, *it1 * *it2);
+       for (auto & it1 : l)
+               for (auto & it2 : l)
+                       add(it1, it2, it1 * it2);
 }
 
 void scalar_products::clear()
@@ -1392,13 +1390,11 @@ ex scalar_products::evaluate(const ex & v1, const ex & v2, const ex & dim) const
 void scalar_products::debugprint() const
 {
        std::cerr << "map size=" << spm.size() << std::endl;
-       spmap::const_iterator i = spm.begin(), end = spm.end();
-       while (i != end) {
-               const spmapkey & k = i->first;
+       for (auto & it : spm) {
+               const spmapkey & k = it.first;
                std::cerr << "item key=";
                k.debugprint();
-               std::cerr << ", value=" << i->second << std::endl;
-               ++i;
+               std::cerr << ", value=" << it.second << std::endl;
        }
 }
 
@@ -1448,13 +1444,13 @@ exvector get_all_dummy_indices(const ex & e)
        exvector p;
        bool nc;
        product_to_exvector(e, p, nc);
-       exvector::const_iterator ip = p.begin(), ipend = p.end();
+       auto ip = p.begin(), ipend = p.end();
        exvector v, v1;
        while (ip != ipend) {
                if (is_a<indexed>(*ip)) {
                        v1 = ex_to<indexed>(*ip).get_dummy_indices();
                        v.insert(v.end(), v1.begin(), v1.end());
-                       exvector::const_iterator ip1 = ip+1;
+                       auto ip1 = ip + 1;
                        while (ip1 != ipend) {
                                if (is_a<indexed>(*ip1)) {
                                        v1 = ex_to<indexed>(*ip).get_dummy_indices(ex_to<indexed>(*ip1));
@@ -1537,15 +1533,12 @@ ex rename_dummy_indices_uniquely(exvector & va, const ex & b, bool modify_va)
                        lst indices_subs = rename_dummy_indices_uniquely(va, vb);
                        if (indices_subs.op(0).nops() > 0) {
                                if (modify_va) {
-                                       for (lst::const_iterator i = ex_to<lst>(indices_subs.op(1)).begin(); i != ex_to<lst>(indices_subs.op(1)).end(); ++i)
-                                               va.push_back(*i);
+                                       for (auto & i : ex_to<lst>(indices_subs.op(1)))
+                                               va.push_back(i);
                                        exvector uncommon_indices;
                                        set_difference(vb.begin(), vb.end(), indices_subs.op(0).begin(), indices_subs.op(0).end(), std::back_insert_iterator<exvector>(uncommon_indices), ex_is_less());
-                                       exvector::const_iterator ip = uncommon_indices.begin(), ipend = uncommon_indices.end();
-                                       while (ip != ipend) {
-                                               va.push_back(*ip);
-                                               ++ip;
-                                       }
+                                       for (auto & ip : uncommon_indices)
+                                               va.push_back(ip);
                                        sort(va.begin(), va.end(), ex_is_less());
                                }
                                return b.subs(ex_to<lst>(indices_subs.op(0)), ex_to<lst>(indices_subs.op(1)), subs_options::no_pattern|subs_options::no_index_renaming);
@@ -1568,8 +1561,7 @@ ex expand_dummy_sum(const ex & e, bool subs_idx)
                else
                        v = get_all_dummy_indices(e_expanded);
                ex result = e_expanded;
-               for(exvector::const_iterator it=v.begin(); it!=v.end(); ++it) {
-                       ex nu = *it;
+               for (const auto & nu : v) {
                        if (ex_to<idx>(nu).get_dim().info(info_flags::nonnegint)) {
                                int idim = ex_to<numeric>(ex_to<idx>(nu).get_dim()).to_int();
                                ex en = 0;
index 3c46b17efa87674b0ab5fbd4a3780ab9899066c0..1b5f8edf7f418b4b773c39887c657c335dd0fa9a 100644 (file)
@@ -92,12 +92,13 @@ matrix::matrix(unsigned r, unsigned c, const lst & l)
        setflag(status_flags::not_shareable);
 
        size_t i = 0;
-       for (lst::const_iterator it = l.begin(); it != l.end(); ++it, ++i) {
+       for (auto & it : l) {
                size_t x = i % c;
                size_t y = i / c;
                if (y >= r)
                        break; // matrix smaller than list: throw away excessive elements
-               m[y*c+x] = *it;
+               m[y*c+x] = it;
+               ++i;
        }
 }
 
@@ -114,10 +115,10 @@ void matrix::read_archive(const archive_node &n, lst &sym_lst)
        m.reserve(row * col);
        // XXX: default ctor inserts a zero element, we need to erase it here.
        m.pop_back();
-       archive_node::archive_node_cit first = n.find_first("m");
-       archive_node::archive_node_cit last = n.find_last("m");
+       auto first = n.find_first("m");
+       auto last = n.find_last("m");
        ++last;
-       for (archive_node::archive_node_cit i=first; i != last; ++i) {
+       for (auto i=first; i != last; ++i) {
                ex e;
                n.find_ex_by_loc(i, e, sym_lst);
                m.push_back(e);
@@ -130,10 +131,8 @@ void matrix::archive(archive_node &n) const
        inherited::archive(n);
        n.add_unsigned("row", row);
        n.add_unsigned("col", col);
-       exvector::const_iterator i = m.begin(), iend = m.end();
-       while (i != iend) {
-               n.add_ex("m", *i);
-               ++i;
+       for (auto & i : m) {
+               n.add_ex("m", i);
        }
 }
 
@@ -221,8 +220,8 @@ ex matrix::eval(int level) const
                for (unsigned c=0; c<col; ++c)
                        m2[r*col+c] = m[r*col+c].eval(level);
        
-       return (new matrix(row, col, m2))->setflag(status_flags::dynallocated |
-                                                  status_flags::evaluated);
+       return (new matrix(row, col, std::move(m2)))->setflag(status_flags::dynallocated |
+                                                             status_flags::evaluated);
 }
 
 ex matrix::subs(const exmap & mp, unsigned options) const
@@ -232,14 +231,14 @@ ex matrix::subs(const exmap & mp, unsigned options) const
                for (unsigned c=0; c<col; ++c)
                        m2[r*col+c] = m[r*col+c].subs(mp, options);
 
-       return matrix(row, col, m2).subs_one_level(mp, options);
+       return matrix(row, col, std::move(m2)).subs_one_level(mp, options);
 }
 
 /** Complex conjugate every matrix entry. */
 ex matrix::conjugate() const
 {
-       exvector * ev = 0;
-       for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i) {
+       std::unique_ptr<exvector> ev(nullptr);
+       for (auto i=m.begin(); i!=m.end(); ++i) {
                ex x = i->conjugate();
                if (ev) {
                        ev->push_back(x);
@@ -248,17 +247,15 @@ ex matrix::conjugate() const
                if (are_ex_trivially_equal(x, *i)) {
                        continue;
                }
-               ev = new exvector;
+               ev.reset(new exvector);
                ev->reserve(m.size());
-               for (exvector::const_iterator j=m.begin(); j!=i; ++j) {
+               for (auto j=m.begin(); j!=i; ++j) {
                        ev->push_back(*j);
                }
                ev->push_back(x);
        }
        if (ev) {
-               ex result = matrix(row, col, *ev);
-               delete ev;
-               return result;
+               return matrix(row, col, std::move(*ev));
        }
        return *this;
 }
@@ -267,18 +264,18 @@ ex matrix::real_part() const
 {
        exvector v;
        v.reserve(m.size());
-       for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i)
-               v.push_back(i->real_part());
-       return matrix(row, col, v);
+       for (auto & i : m)
+               v.push_back(i.real_part());
+       return matrix(row, col, std::move(v));
 }
 
 ex matrix::imag_part() const
 {
        exvector v;
        v.reserve(m.size());
-       for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i)
-               v.push_back(i->imag_part());
-       return matrix(row, col, v);
+       for (auto & i : m)
+               v.push_back(i.imag_part());
+       return matrix(row, col, std::move(v));
 }
 
 // protected
@@ -560,12 +557,11 @@ matrix matrix::add(const matrix & other) const
                throw std::logic_error("matrix::add(): incompatible matrices");
        
        exvector sum(this->m);
-       exvector::iterator i = sum.begin(), end = sum.end();
-       exvector::const_iterator ci = other.m.begin();
-       while (i != end)
-               *i++ += *ci++;
+       auto ci = other.m.begin();
+       for (auto & i : sum)
+               i += *ci++;
        
-       return matrix(row,col,sum);
+       return matrix(row, col, std::move(sum));
 }
 
 
@@ -578,12 +574,11 @@ matrix matrix::sub(const matrix & other) const
                throw std::logic_error("matrix::sub(): incompatible matrices");
        
        exvector dif(this->m);
-       exvector::iterator i = dif.begin(), end = dif.end();
-       exvector::const_iterator ci = other.m.begin();
-       while (i != end)
-               *i++ -= *ci++;
+       auto ci = other.m.begin();
+       for (auto & i : dif)
+               i -= *ci++;
        
-       return matrix(row,col,dif);
+       return matrix(row, col, std::move(dif));
 }
 
 
@@ -606,7 +601,7 @@ matrix matrix::mul(const matrix & other) const
                                prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]);
                }
        }
-       return matrix(row, other.col, prod);
+       return matrix(row, other.col, std::move(prod));
 }
 
 
@@ -619,7 +614,7 @@ matrix matrix::mul(const numeric & other) const
                for (unsigned c=0; c<col; ++c)
                        prod[r*col+c] = m[r*col+c] * other;
 
-       return matrix(row, col, prod);
+       return matrix(row, col, std::move(prod));
 }
 
 
@@ -635,7 +630,7 @@ matrix matrix::mul_scalar(const ex & other) const
                for (unsigned c=0; c<col; ++c)
                        prod[r*col+c] = m[r*col+c] * other;
 
-       return matrix(row, col, prod);
+       return matrix(row, col, std::move(prod));
 }
 
 
@@ -721,7 +716,7 @@ matrix matrix::transpose() const
                for (unsigned c=0; c<this->rows(); ++c)
                        trans[r*this->rows()+c] = m[c*this->cols()+r];
        
-       return matrix(this->cols(),this->rows(),trans);
+       return matrix(this->cols(), this->rows(), std::move(trans));
 }
 
 /** Determinant of square matrix.  This routine doesn't actually calculate the
@@ -748,18 +743,16 @@ ex matrix::determinant(unsigned algo) const
        bool numeric_flag = true;
        bool normal_flag = false;
        unsigned sparse_count = 0;  // counts non-zero elements
-       exvector::const_iterator r = m.begin(), rend = m.end();
-       while (r != rend) {
-               if (!r->info(info_flags::numeric))
+       for (auto r : m) {
+               if (!r.info(info_flags::numeric))
                        numeric_flag = false;
                exmap srl;  // symbol replacement list
-               ex rtest = r->to_rational(srl);
+               ex rtest = r.to_rational(srl);
                if (!rtest.is_zero())
                        ++sparse_count;
                if (!rtest.info(info_flags::crational_polynomial) &&
-                        rtest.info(info_flags::rational_function))
+                    rtest.info(info_flags::rational_function))
                        normal_flag = true;
-               ++r;
        }
        
        // Here is the heuristics in case this routine has to decide:
@@ -842,23 +835,22 @@ ex matrix::determinant(unsigned algo) const
                        }
                        std::sort(c_zeros.begin(),c_zeros.end());
                        std::vector<unsigned> pre_sort;
-                       for (std::vector<uintpair>::const_iterator i=c_zeros.begin(); i!=c_zeros.end(); ++i)
-                               pre_sort.push_back(i->second);
+                       for (auto & i : c_zeros)
+                               pre_sort.push_back(i.second);
                        std::vector<unsigned> pre_sort_test(pre_sort); // permutation_sign() modifies the vector so we make a copy here
                        int sign = permutation_sign(pre_sort_test.begin(), pre_sort_test.end());
                        exvector result(row*col);  // represents sorted matrix
                        unsigned c = 0;
-                       for (std::vector<unsigned>::const_iterator i=pre_sort.begin();
-                                i!=pre_sort.end();
-                                ++i,++c) {
+                       for (auto & it : pre_sort) {
                                for (unsigned r=0; r<row; ++r)
-                                       result[r*col+c] = m[r*col+(*i)];
+                                       result[r*col+c] = m[r*col+it];
+                               ++c;
                        }
                        
                        if (normal_flag)
-                               return (sign*matrix(row,col,result).determinant_minor()).normal();
+                               return (sign*matrix(row, col, std::move(result)).determinant_minor()).normal();
                        else
-                               return sign*matrix(row,col,result).determinant_minor();
+                               return sign*matrix(row, col, std::move(result)).determinant_minor();
                }
        }
 }
@@ -904,11 +896,11 @@ ex matrix::charpoly(const ex & lambda) const
                throw (std::logic_error("matrix::charpoly(): matrix not square"));
        
        bool numeric_flag = true;
-       exvector::const_iterator r = m.begin(), rend = m.end();
-       while (r!=rend && numeric_flag==true) {
-               if (!r->info(info_flags::numeric))
+       for (auto & r : m) {
+               if (!r.info(info_flags::numeric)) {
                        numeric_flag = false;
-               ++r;
+                       break;
+               }
        }
        
        // The pure numeric case is traditionally rather common.  Hence, it is
@@ -1019,11 +1011,11 @@ matrix matrix::solve(const matrix & vars,
        
        // Gather some statistical information about the augmented matrix:
        bool numeric_flag = true;
-       exvector::const_iterator r = aug.m.begin(), rend = aug.m.end();
-       while (r!=rend && numeric_flag==true) {
-               if (!r->info(info_flags::numeric))
+       for (auto & r : aug.m) {
+               if (!r.info(info_flags::numeric)) {
                        numeric_flag = false;
-               ++r;
+                       break;
+               }
        }
        
        // Here is the heuristics in case this routine has to decide:
@@ -1403,11 +1395,9 @@ int matrix::fraction_free_elimination(const bool det)
        matrix tmp_n(*this);
        matrix tmp_d(m,n);  // for denominators, if needed
        exmap srl;  // symbol replacement list
-       exvector::const_iterator cit = this->m.begin(), citend = this->m.end();
-       exvector::iterator tmp_n_it = tmp_n.m.begin(), tmp_d_it = tmp_d.m.begin();
-       while (cit != citend) {
-               ex nd = cit->normal().to_rational(srl).numer_denom();
-               ++cit;
+       auto tmp_n_it = tmp_n.m.begin(), tmp_d_it = tmp_d.m.begin();
+       for (auto & it : this->m) {
+               ex nd = it.normal().to_rational(srl).numer_denom();
                *tmp_n_it++ = nd.op(0);
                *tmp_d_it++ = nd.op(1);
        }
@@ -1476,11 +1466,10 @@ int matrix::fraction_free_elimination(const bool det)
        }
 
        // repopulate *this matrix:
-       exvector::iterator it = this->m.begin(), itend = this->m.end();
        tmp_n_it = tmp_n.m.begin();
        tmp_d_it = tmp_d.m.begin();
-       while (it != itend)
-               *it++ = ((*tmp_n_it++)/(*tmp_d_it++)).subs(srl, subs_options::no_pattern);
+       for (auto & it : this->m)
+               it = ((*tmp_n_it++)/(*tmp_d_it++)).subs(srl, subs_options::no_pattern);
        
        return sign;
 }
@@ -1541,34 +1530,35 @@ int matrix::pivot(unsigned ro, unsigned co, bool symbolic)
  */
 bool matrix::is_zero_matrix() const
 {
-       for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i) 
-               if(!(i->is_zero()))
+       for (auto & i : m)
+               if (!i.is_zero())
                        return false;
        return true;
 }
 
 ex lst_to_matrix(const lst & l)
 {
-       lst::const_iterator itr, itc;
-
        // Find number of rows and columns
        size_t rows = l.nops(), cols = 0;
-       for (itr = l.begin(); itr != l.end(); ++itr) {
-               if (!is_a<lst>(*itr))
+       for (auto & itr : l) {
+               if (!is_a<lst>(itr))
                        throw (std::invalid_argument("lst_to_matrix: argument must be a list of lists"));
-               if (itr->nops() > cols)
-                       cols = itr->nops();
+               if (itr.nops() > cols)
+                       cols = itr.nops();
        }
 
        // Allocate and fill matrix
        matrix &M = *new matrix(rows, cols);
        M.setflag(status_flags::dynallocated);
 
-       unsigned i;
-       for (itr = l.begin(), i = 0; itr != l.end(); ++itr, ++i) {
-               unsigned j;
-               for (itc = ex_to<lst>(*itr).begin(), j = 0; itc != ex_to<lst>(*itr).end(); ++itc, ++j)
-                       M(i, j) = *itc;
+       unsigned i = 0;
+       for (auto & itr : l) {
+               unsigned j = 0;
+               for (auto & itc : ex_to<lst>(itr)) {
+                       M(i, j) = itc;
+                       ++j;
+               }
+               ++i;
        }
 
        return M;
@@ -1576,16 +1566,17 @@ ex lst_to_matrix(const lst & l)
 
 ex diag_matrix(const lst & l)
 {
-       lst::const_iterator it;
        size_t dim = l.nops();
 
        // Allocate and fill matrix
        matrix &M = *new matrix(dim, dim);
        M.setflag(status_flags::dynallocated);
 
-       unsigned i;
-       for (it = l.begin(), i = 0; it != l.end(); ++it, ++i)
-               M(i, i) = *it;
+       unsigned i = 0;
+       for (auto & it : l) {
+               M(i, i) = it;
+               ++i;
+       }
 
        return M;
 }
index f91ac25f56ba443fe2b77a6a95184917d39977d3..943095bb3a9c0e1a88aa023c37916bc701178eae 100644 (file)
@@ -145,15 +145,13 @@ void mul::do_print(const print_context & c, unsigned level) const
 
        print_overall_coeff(c, "*");
 
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
        bool first = true;
-       while (it != itend) {
+       for (auto & it : seq) {
                if (!first)
                        c.s << '*';
                else
                        first = false;
-               recombine_pair_to_ex(*it).print(c, precedence());
-               ++it;
+               recombine_pair_to_ex(it).print(c, precedence());
        }
 
        if (precedence() <= level)
@@ -169,15 +167,13 @@ void mul::do_print_latex(const print_latex & c, unsigned level) const
 
        // Separate factors into those with negative numeric exponent
        // and all others
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
        exvector neg_powers, others;
-       while (it != itend) {
-               GINAC_ASSERT(is_exactly_a<numeric>(it->coeff));
-               if (ex_to<numeric>(it->coeff).is_negative())
-                       neg_powers.push_back(recombine_pair_to_ex(expair(it->rest, -(it->coeff))));
+       for (auto & it : seq) {
+               GINAC_ASSERT(is_exactly_a<numeric>(it.coeff));
+               if (ex_to<numeric>(it.coeff).is_negative())
+                       neg_powers.push_back(recombine_pair_to_ex(expair(it.rest, -it.coeff)));
                else
-                       others.push_back(recombine_pair_to_ex(*it));
-               ++it;
+                       others.push_back(recombine_pair_to_ex(it));
        }
 
        if (!neg_powers.empty()) {
@@ -192,11 +188,9 @@ void mul::do_print_latex(const print_latex & c, unsigned level) const
        } else {
 
                // All other factors are printed in the ordinary way
-               exvector::const_iterator vit = others.begin(), vitend = others.end();
-               while (vit != vitend) {
+               for (auto & vit : others) {
                        c.s << ' ';
-                       vit->print(c, precedence());
-                       ++vit;
+                       vit.print(c, precedence());
                }
        }
 
@@ -219,7 +213,7 @@ void mul::do_print_csrc(const print_csrc & c, unsigned level) const
        }
 
        // Print arguments, separated by "*" or "/"
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
+       auto it = seq.begin(), itend = seq.end();
        while (it != itend) {
 
                // If the first argument is a negative integer power, it gets printed as "1.0/<expr>"
@@ -236,11 +230,9 @@ void mul::do_print_csrc(const print_csrc & c, unsigned level) const
                if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1))
                        it->rest.print(c, precedence());
                else if (it->coeff.info(info_flags::negint))
-                       // Outer parens around ex needed for broken GCC parser:
-                       (ex(power(it->rest, -ex_to<numeric>(it->coeff)))).print(c, level);
+                       ex(power(it->rest, -ex_to<numeric>(it->coeff))).print(c, level);
                else
-                       // Outer parens around ex needed for broken GCC parser:
-                       (ex(power(it->rest, ex_to<numeric>(it->coeff)))).print(c, level);
+                       ex(power(it->rest, ex_to<numeric>(it->coeff))).print(c, level);
 
                if (needclosingparenthesis)
                        c.s << ")";
@@ -285,22 +277,18 @@ bool mul::info(unsigned inf) const
                case info_flags::even:
                case info_flags::crational_polynomial:
                case info_flags::rational_function: {
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               if (!(recombine_pair_to_ex(*i).info(inf)))
+                       for (auto & it : seq) {
+                               if (!recombine_pair_to_ex(it).info(inf))
                                        return false;
-                               ++i;
                        }
                        if (overall_coeff.is_equal(*_num1_p) && inf == info_flags::even)
                                return true;
                        return overall_coeff.info(inf);
                }
                case info_flags::algebraic: {
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               if ((recombine_pair_to_ex(*i).info(inf)))
+                       for (auto & it : seq) {
+                               if (recombine_pair_to_ex(it).info(inf))
                                        return true;
-                               ++i;
                        }
                        return false;
                }
@@ -314,9 +302,8 @@ bool mul::info(unsigned inf) const
                                return false;
 
                        bool pos = true;
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               const ex& factor = recombine_pair_to_ex(*i++);
+                       for (auto & it : seq) {
+                               const ex& factor = recombine_pair_to_ex(it);
                                if (factor.info(info_flags::positive))
                                        continue;
                                else if (factor.info(info_flags::negative))
@@ -333,9 +320,8 @@ bool mul::info(unsigned inf) const
                        if  (flags & status_flags::is_positive)
                                return true;
                        bool pos = true;
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               const ex& factor = recombine_pair_to_ex(*i++);
+                       for (auto & it : seq) {
+                               const ex& factor = recombine_pair_to_ex(it);
                                if (factor.info(info_flags::nonnegative) || factor.info(info_flags::positive))
                                        continue;
                                else if (factor.info(info_flags::negative))
@@ -348,9 +334,8 @@ bool mul::info(unsigned inf) const
                case info_flags::posint:
                case info_flags::negint: {
                        bool pos = true;
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               const ex& factor = recombine_pair_to_ex(*i++);
+                       for (auto & it : seq) {
+                               const ex& factor = recombine_pair_to_ex(it);
                                if (factor.info(info_flags::posint))
                                        continue;
                                else if (factor.info(info_flags::negint))
@@ -366,9 +351,8 @@ bool mul::info(unsigned inf) const
                }
                case info_flags::nonnegint: {
                        bool pos = true;
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               const ex& factor = recombine_pair_to_ex(*i++);
+                       for (auto & it : seq) {
+                               const ex& factor = recombine_pair_to_ex(it);
                                if (factor.info(info_flags::nonnegint) || factor.info(info_flags::posint))
                                        continue;
                                else if (factor.info(info_flags::negint))
@@ -387,12 +371,10 @@ bool mul::info(unsigned inf) const
                                return true;
                        if (flags & (status_flags::is_positive | status_flags::is_negative))
                                return false;
-                       epvector::const_iterator i = seq.begin(), end = seq.end();
-                       while (i != end) {
-                               const ex& term = recombine_pair_to_ex(*i);
+                       for (auto & it : seq) {
+                               const ex& term = recombine_pair_to_ex(it);
                                if (term.info(info_flags::positive) || term.info(info_flags::negative))
                                        return false;
-                               ++i;
                        }
                        setflag(status_flags::purely_indefinite);
                        return true;
@@ -403,9 +385,9 @@ bool mul::info(unsigned inf) const
 
 bool mul::is_polynomial(const ex & var) const
 {
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
-               if (!i->rest.is_polynomial(var) ||
-                   (i->rest.has(var) && !i->coeff.info(info_flags::nonnegint))) {
+       for (auto & it : seq) {
+               if (!it.rest.is_polynomial(var) ||
+                   (it.rest.has(var) && !it.coeff.info(info_flags::nonnegint))) {
                        return false;
                }
        }
@@ -416,15 +398,13 @@ int mul::degree(const ex & s) const
 {
        // Sum up degrees of factors
        int deg_sum = 0;
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               if (ex_to<numeric>(i->coeff).is_integer())
-                       deg_sum += recombine_pair_to_ex(*i).degree(s);
+       for (auto & it : seq) {
+               if (ex_to<numeric>(it.coeff).is_integer())
+                       deg_sum += recombine_pair_to_ex(it).degree(s);
                else {
-                       if (i->rest.has(s))
+                       if (it.rest.has(s))
                                throw std::runtime_error("mul::degree() undefined degree because of non-integer exponent");
                }
-               ++i;
        }
        return deg_sum;
 }
@@ -433,15 +413,13 @@ int mul::ldegree(const ex & s) const
 {
        // Sum up degrees of factors
        int deg_sum = 0;
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               if (ex_to<numeric>(i->coeff).is_integer())
-                       deg_sum += recombine_pair_to_ex(*i).ldegree(s);
+       for (auto & it : seq) {
+               if (ex_to<numeric>(it.coeff).is_integer())
+                       deg_sum += recombine_pair_to_ex(it).ldegree(s);
                else {
-                       if (i->rest.has(s))
+                       if (it.rest.has(s))
                                throw std::runtime_error("mul::ldegree() undefined degree because of non-integer exponent");
                }
-               ++i;
        }
        return deg_sum;
 }
@@ -454,19 +432,15 @@ ex mul::coeff(const ex & s, int n) const
        if (n==0) {
                // product of individual coeffs
                // if a non-zero power of s is found, the resulting product will be 0
-               epvector::const_iterator i = seq.begin(), end = seq.end();
-               while (i != end) {
-                       coeffseq.push_back(recombine_pair_to_ex(*i).coeff(s,n));
-                       ++i;
-               }
+               for (auto & it : seq)
+                       coeffseq.push_back(recombine_pair_to_ex(it).coeff(s,n));
                coeffseq.push_back(overall_coeff);
                return (new mul(coeffseq))->setflag(status_flags::dynallocated);
        }
        
-       epvector::const_iterator i = seq.begin(), end = seq.end();
        bool coeff_found = false;
-       while (i != end) {
-               ex t = recombine_pair_to_ex(*i);
+       for (auto & it : seq) {
+               ex t = recombine_pair_to_ex(it);
                ex c = t.coeff(s, n);
                if (!c.is_zero()) {
                        coeffseq.push_back(c);
@@ -474,7 +448,6 @@ ex mul::coeff(const ex & s, int n) const
                } else {
                        coeffseq.push_back(t);
                }
-               ++i;
        }
        if (coeff_found) {
                coeffseq.push_back(overall_coeff);
@@ -525,10 +498,8 @@ ex mul::eval(int level) const
                const add & addref = ex_to<add>((*seq.begin()).rest);
                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));
-                       ++i;
+               for (auto & it : addref.seq) {
+                       distrseq.push_back(addref.combine_pair_with_coeff_to_pair(it, overall_coeff));
                }
                return (new add(std::move(distrseq),
                                ex_to<numeric>(addref.overall_coeff).
@@ -538,9 +509,8 @@ ex mul::eval(int level) const
                // Strip the content and the unit part from each term. Thus
                // things like (-x+a)*(3*x-3*a) automagically turn into - 3*(x-a)^2
 
-               epvector::const_iterator last = seq.end();
-               epvector::const_iterator i = seq.begin();
-               epvector::const_iterator j = seq.begin();
+               auto i = seq.begin(), last = seq.end();
+               auto j = seq.begin();
                epvector s;
                numeric oc = *_num1_p;
                bool something_changed = false;
@@ -621,11 +591,9 @@ ex mul::evalf(int level) const
        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));
-               ++i;
+       for (auto & it : seq) {
+               s.push_back(combine_ex_with_coeff_to_pair(it.rest.evalf(level),
+                                                         it.coeff));
        }
        return mul(std::move(s), overall_coeff.evalf(level));
 }
@@ -634,11 +602,11 @@ void mul::find_real_imag(ex & rp, ex & ip) const
 {
        rp = overall_coeff.real_part();
        ip = overall_coeff.imag_part();
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
-               ex factor = recombine_pair_to_ex(*i);
+       for (auto & it : seq) {
+               ex factor = recombine_pair_to_ex(it);
                ex new_rp = factor.real_part();
                ex new_ip = factor.imag_part();
-               if(new_ip.is_zero()) {
+               if (new_ip.is_zero()) {
                        rp *= new_rp;
                        ip *= new_rp;
                } else {
@@ -681,15 +649,13 @@ ex mul::evalm() const
        bool have_matrix = false;
        epvector::iterator the_matrix;
 
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               const ex &m = recombine_pair_to_ex(*i).evalm();
+       for (auto & it : seq) {
+               const ex &m = recombine_pair_to_ex(it).evalm();
                s.push_back(split_ex_to_pair(m));
                if (is_a<matrix>(m)) {
                        have_matrix = true;
                        the_matrix = s.end() - 1;
                }
-               ++i;
        }
 
        if (have_matrix) {
@@ -711,12 +677,9 @@ ex mul::eval_ncmul(const exvector & v) const
                return inherited::eval_ncmul(v);
 
        // Find first noncommutative element and call its eval_ncmul()
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               if (i->rest.return_type() == return_types::noncommutative)
-                       return i->rest.eval_ncmul(v);
-               ++i;
-       }
+       for (auto & it : seq)
+               if (it.rest.return_type() == return_types::noncommutative)
+                       return it.rest.eval_ncmul(v);
        return inherited::eval_ncmul(v);
 }
 
@@ -824,25 +787,25 @@ ex mul::algebraic_subs_mul(const exmap & m, unsigned options) const
        ex divide_by = 1;
        ex multiply_by = 1;
 
-       for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
+       for (auto & it : m) {
 
-               if (is_exactly_a<mul>(it->first)) {
+               if (is_exactly_a<mul>(it.first)) {
 retry1:
                        int nummatches = std::numeric_limits<int>::max();
                        std::vector<bool> currsubsed(nops(), false);
                        exmap repls;
                        
-                       if(!algebraic_match_mul_with_mul(*this, it->first, repls, 0, nummatches, subsed, currsubsed))
+                       if (!algebraic_match_mul_with_mul(*this, it.first, repls, 0, nummatches, subsed, currsubsed))
                                continue;
 
                        for (size_t j=0; j<subsed.size(); j++)
                                if (currsubsed[j])
                                        subsed[j] = true;
                        ex subsed_pattern
-                               = it->first.subs(repls, subs_options::no_pattern);
+                               = it.first.subs(repls, subs_options::no_pattern);
                        divide_by *= power(subsed_pattern, nummatches);
                        ex subsed_result
-                               = it->second.subs(repls, subs_options::no_pattern);
+                               = it.second.subs(repls, subs_options::no_pattern);
                        multiply_by *= power(subsed_result, nummatches);
                        goto retry1;
 
@@ -851,13 +814,13 @@ retry1:
                        for (size_t j=0; j<this->nops(); j++) {
                                int nummatches = std::numeric_limits<int>::max();
                                exmap repls;
-                               if (!subsed[j] && tryfactsubs(op(j), it->first, nummatches, repls)){
+                               if (!subsed[j] && tryfactsubs(op(j), it.first, nummatches, repls)){
                                        subsed[j] = true;
                                        ex subsed_pattern
-                                               = it->first.subs(repls, subs_options::no_pattern);
+                                               = it.first.subs(repls, subs_options::no_pattern);
                                        divide_by *= power(subsed_pattern, nummatches);
                                        ex subsed_result
-                                               = it->second.subs(repls, subs_options::no_pattern);
+                                               = it.second.subs(repls, subs_options::no_pattern);
                                        multiply_by *= power(subsed_result, nummatches);
                                }
                        }
@@ -881,8 +844,8 @@ ex mul::conjugate() const
 {
        // The base class' method is wrong here because we have to be careful at
        // branch cuts. power::conjugate takes care of that already, so use it.
-       epvector *newepv = 0;
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+       std::unique_ptr<epvector> newepv(nullptr);
+       for (auto i=seq.begin(); i!=seq.end(); ++i) {
                if (newepv) {
                        newepv->push_back(split_ex_to_pair(recombine_pair_to_ex(*i).conjugate()));
                        continue;
@@ -892,9 +855,9 @@ ex mul::conjugate() const
                if (c.is_equal(x)) {
                        continue;
                }
-               newepv = new epvector;
+               newepv.reset(new epvector);
                newepv->reserve(seq.size());
-               for (epvector::const_iterator j=seq.begin(); j!=i; ++j) {
+               for (auto j=seq.begin(); j!=i; ++j) {
                        newepv->push_back(*j);
                }
                newepv->push_back(split_ex_to_pair(c));
@@ -903,9 +866,7 @@ ex mul::conjugate() const
        if (!newepv && are_ex_trivially_equal(x, overall_coeff)) {
                return *this;
        }
-       ex result = thisexpairseq(newepv ? *newepv : seq, x);
-       delete newepv;
-       return result;
+       return thisexpairseq(newepv ? std::move(*newepv) : seq, x);
 }
 
 
@@ -921,8 +882,8 @@ ex mul::derivative(const symbol & s) const
        
        // D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c)
        epvector mulseq = seq;
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       epvector::iterator i2 = mulseq.begin();
+       auto i = seq.begin(), end = seq.end();
+       auto i2 = mulseq.begin();
        while (i != end) {
                expair ep = split_ex_to_pair(power(i->rest, i->coeff - _ex1) *
                                             i->rest.diff(s));
@@ -978,12 +939,10 @@ return_type_t mul::return_type_tinfo() const
                return make_return_type_t<mul>(); // mul without factors: should not happen
        
        // return type_info of first noncommutative element
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               if (i->rest.return_type() == return_types::noncommutative)
-                       return i->rest.return_type_tinfo();
-               ++i;
-       }
+       for (auto & it : seq)
+               if (it.rest.return_type() == return_types::noncommutative)
+                       return it.rest.return_type_tinfo();
+
        // no noncommutative element found, should not happen
        return make_return_type_t<mul>();
 }
@@ -1097,8 +1056,8 @@ bool mul::can_make_flat(const expair & p) const
 bool mul::can_be_further_expanded(const ex & e)
 {
        if (is_exactly_a<mul>(e)) {
-               for (epvector::const_iterator cit = ex_to<mul>(e).seq.begin(); cit != ex_to<mul>(e).seq.end(); ++cit) {
-                       if (is_exactly_a<add>(cit->rest) && cit->coeff.info(info_flags::posint))
+               for (auto & it : ex_to<mul>(e).seq) {
+                       if (is_exactly_a<add>(it.rest) && it.coeff.info(info_flags::posint))
                                return true;
                }
        } else if (is_exactly_a<power>(e)) {
@@ -1140,43 +1099,39 @@ ex mul::expand(unsigned options) const
        epvector non_adds;
        non_adds.reserve(expanded_seq.size());
 
-       for (epvector::const_iterator cit = expanded_seq.begin(); cit != expanded_seq.end(); ++cit) {
-               if (is_exactly_a<add>(cit->rest) &&
-                       (cit->coeff.is_equal(_ex1))) {
+       for (const auto & cit : expanded_seq) {
+               if (is_exactly_a<add>(cit.rest) &&
+                       (cit.coeff.is_equal(_ex1))) {
                        if (is_exactly_a<add>(last_expanded)) {
 
                                // Expand a product of two sums, aggressive version.
                                // Caring for the overall coefficients in separate loops can
                                // sometimes give a performance gain of up to 15%!
 
-                               const int sizedifference = ex_to<add>(last_expanded).seq.size()-ex_to<add>(cit->rest).seq.size();
+                               const int sizedifference = ex_to<add>(last_expanded).seq.size()-ex_to<add>(cit.rest).seq.size();
                                // add2 is for the inner loop and should be the bigger of the two sums
                                // in the presence of asymptotically good sorting:
-                               const add& add1 = (sizedifference<0 ? ex_to<add>(last_expanded) : ex_to<add>(cit->rest));
-                               const add& add2 = (sizedifference<0 ? ex_to<add>(cit->rest) : ex_to<add>(last_expanded));
-                               const epvector::const_iterator add1begin = add1.seq.begin();
-                               const epvector::const_iterator add1end   = add1.seq.end();
-                               const epvector::const_iterator add2begin = add2.seq.begin();
-                               const epvector::const_iterator add2end   = add2.seq.end();
+                               const add& add1 = (sizedifference<0 ? ex_to<add>(last_expanded) : ex_to<add>(cit.rest));
+                               const add& add2 = (sizedifference<0 ? ex_to<add>(cit.rest) : ex_to<add>(last_expanded));
                                epvector distrseq;
                                distrseq.reserve(add1.seq.size()+add2.seq.size());
 
                                // Multiply add2 with the overall coefficient of add1 and append it to distrseq:
                                if (!add1.overall_coeff.is_zero()) {
                                        if (add1.overall_coeff.is_equal(_ex1))
-                                               distrseq.insert(distrseq.end(),add2begin,add2end);
+                                               distrseq.insert(distrseq.end(), add2.seq.begin(), add2.seq.end());
                                        else
-                                               for (epvector::const_iterator i=add2begin; i!=add2end; ++i)
-                                                       distrseq.push_back(expair(i->rest, ex_to<numeric>(i->coeff).mul_dyn(ex_to<numeric>(add1.overall_coeff))));
+                                               for (const auto & i : add2.seq)
+                                                       distrseq.push_back(expair(i.rest, ex_to<numeric>(i.coeff).mul_dyn(ex_to<numeric>(add1.overall_coeff))));
                                }
 
                                // Multiply add1 with the overall coefficient of add2 and append it to distrseq:
                                if (!add2.overall_coeff.is_zero()) {
                                        if (add2.overall_coeff.is_equal(_ex1))
-                                               distrseq.insert(distrseq.end(),add1begin,add1end);
+                                               distrseq.insert(distrseq.end(), add1.seq.begin(), add1.seq.end());
                                        else
-                                               for (epvector::const_iterator i=add1begin; i!=add1end; ++i)
-                                                       distrseq.push_back(expair(i->rest, ex_to<numeric>(i->coeff).mul_dyn(ex_to<numeric>(add2.overall_coeff))));
+                                               for (const auto & i : add1.seq)
+                                                       distrseq.push_back(expair(i.rest, ex_to<numeric>(i.coeff).mul_dyn(ex_to<numeric>(add2.overall_coeff))));
                                }
 
                                // Compute the new overall coefficient and put it together:
@@ -1186,12 +1141,12 @@ ex mul::expand(unsigned options) const
                                lst dummy_subs;
 
                                if (!skip_idx_rename) {
-                                       for (epvector::const_iterator i=add1begin; i!=add1end; ++i) {
-                                               add_indices = get_all_dummy_indices_safely(i->rest);
+                                       for (const auto & i : add1.seq) {
+                                               add_indices = get_all_dummy_indices_safely(i.rest);
                                                add1_dummy_indices.insert(add1_dummy_indices.end(), add_indices.begin(), add_indices.end());
                                        }
-                                       for (epvector::const_iterator i=add2begin; i!=add2end; ++i) {
-                                               add_indices = get_all_dummy_indices_safely(i->rest);
+                                       for (const auto & i : add2.seq) {
+                                               add_indices = get_all_dummy_indices_safely(i.rest);
                                                add2_dummy_indices.insert(add2_dummy_indices.end(), add_indices.begin(), add_indices.end());
                                        }
 
@@ -1201,37 +1156,37 @@ ex mul::expand(unsigned options) const
                                }
 
                                // Multiply explicitly all non-numeric terms of add1 and add2:
-                               for (epvector::const_iterator i2=add2begin; i2!=add2end; ++i2) {
+                               for (const auto & i2 : add2.seq) {
                                        // We really have to combine terms here in order to compactify
                                        // the result.  Otherwise it would become waayy tooo bigg.
                                        numeric oc(*_num0_p);
                                        epvector distrseq2;
                                        distrseq2.reserve(add1.seq.size());
                                        const ex i2_new = (skip_idx_rename || (dummy_subs.op(0).nops() == 0) ?
-                                                       i2->rest :
-                                                       i2->rest.subs(ex_to<lst>(dummy_subs.op(0)), 
-                                                               ex_to<lst>(dummy_subs.op(1)), subs_options::no_pattern));
-                                       for (epvector::const_iterator i1=add1begin; i1!=add1end; ++i1) {
+                                                       i2.rest :
+                                                       i2.rest.subs(ex_to<lst>(dummy_subs.op(0)),
+                                                                    ex_to<lst>(dummy_subs.op(1)), subs_options::no_pattern));
+                                       for (const auto & i1 : add1.seq) {
                                                // Don't push_back expairs which might have a rest that evaluates to a numeric,
                                                // since that would violate an invariant of expairseq:
-                                               const ex rest = (new mul(i1->rest, i2_new))->setflag(status_flags::dynallocated);
+                                               const ex rest = (new mul(i1.rest, i2_new))->setflag(status_flags::dynallocated);
                                                if (is_exactly_a<numeric>(rest)) {
-                                                       oc += ex_to<numeric>(rest).mul(ex_to<numeric>(i1->coeff).mul(ex_to<numeric>(i2->coeff)));
+                                                       oc += ex_to<numeric>(rest).mul(ex_to<numeric>(i1.coeff).mul(ex_to<numeric>(i2.coeff)));
                                                } else {
-                                                       distrseq2.push_back(expair(rest, ex_to<numeric>(i1->coeff).mul_dyn(ex_to<numeric>(i2->coeff))));
+                                                       distrseq2.push_back(expair(rest, ex_to<numeric>(i1.coeff).mul_dyn(ex_to<numeric>(i2.coeff))));
                                                }
                                        }
                                        tmp_accu += (new add(distrseq2, oc))->setflag(status_flags::dynallocated);
-                               } 
+                               }
                                last_expanded = tmp_accu;
                        } else {
                                if (!last_expanded.is_equal(_ex1))
                                        non_adds.push_back(split_ex_to_pair(last_expanded));
-                               last_expanded = cit->rest;
+                               last_expanded = cit.rest;
                        }
 
                } else {
-                       non_adds.push_back(*cit);
+                       non_adds.push_back(cit);
                }
        }
 
@@ -1299,8 +1254,7 @@ ex mul::expand(unsigned options) const
  *    had to be changed. */
 epvector mul::expandchildren(unsigned options) const
 {
-       const epvector::const_iterator last = seq.end();
-       epvector::const_iterator cit = seq.begin();
+       auto cit = seq.begin(), last = seq.end();
        while (cit!=last) {
                const ex & factor = recombine_pair_to_ex(*cit);
                const ex & expanded_factor = factor.expand(options);
@@ -1311,7 +1265,7 @@ epvector mul::expandchildren(unsigned options) const
                        s.reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
-                       epvector::const_iterator cit2 = seq.begin();
+                       auto cit2 = seq.begin();
                        while (cit2!=cit) {
                                s.push_back(*cit2);
                                ++cit2;
index 512edf218aac2a29ada66e2db400a1f61a6a944a..b37904bb76bd2dde96e48e8fa6bc6c5398b48a1a 100644 (file)
@@ -132,11 +132,10 @@ ex ncmul::expand(unsigned options) const
        size_t number_of_expanded_terms = 1;
 
        size_t current_position = 0;
-       exvector::const_iterator last = expanded_seq.end();
-       for (exvector::const_iterator cit=expanded_seq.begin(); cit!=last; ++cit) {
-               if (is_exactly_a<add>(*cit)) {
+       for (auto & it : expanded_seq) {
+               if (is_exactly_a<add>(it)) {
                        positions_of_adds[number_of_adds] = current_position;
-                       size_t num_ops = cit->nops();
+                       size_t num_ops = it.nops();
                        number_of_add_operands[number_of_adds] = num_ops;
                        number_of_expanded_terms *= num_ops;
                        number_of_adds++;
@@ -204,11 +203,8 @@ int ncmul::degree(const ex & s) const
 
        // Sum up degrees of factors
        int deg_sum = 0;
-       exvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               deg_sum += i->degree(s);
-               ++i;
-       }
+       for (auto & i : seq)
+               deg_sum += i.degree(s);
        return deg_sum;
 }
 
@@ -219,11 +215,8 @@ int ncmul::ldegree(const ex & s) const
 
        // Sum up degrees of factors
        int deg_sum = 0;
-       exvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               deg_sum += i->degree(s);
-               ++i;
-       }
+       for (auto & i : seq)
+               deg_sum += i.degree(s);
        return deg_sum;
 }
 
@@ -238,28 +231,24 @@ ex ncmul::coeff(const ex & s, int n) const
        if (n == 0) {
                // product of individual coeffs
                // if a non-zero power of s is found, the resulting product will be 0
-               exvector::const_iterator it=seq.begin();
-               while (it!=seq.end()) {
-                       coeffseq.push_back((*it).coeff(s,n));
-                       ++it;
-               }
-               return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
+               for (auto & it : seq)
+                       coeffseq.push_back(it.coeff(s,n));
+               return (new ncmul(std::move(coeffseq),1))->setflag(status_flags::dynallocated);
        }
                 
-       exvector::const_iterator i = seq.begin(), end = seq.end();
        bool coeff_found = false;
-       while (i != end) {
-               ex c = i->coeff(s,n);
+       for (auto & i : seq) {
+               ex c = i.coeff(s,n);
                if (c.is_zero()) {
-                       coeffseq.push_back(*i);
+                       coeffseq.push_back(i);
                } else {
                        coeffseq.push_back(c);
                        coeff_found = true;
                }
-               ++i;
        }
 
-       if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
+       if (coeff_found)
+               return (new ncmul(std::move(coeffseq), 1))->setflag(status_flags::dynallocated);
        
        return _ex0;
 }
@@ -319,16 +308,14 @@ ex ncmul::eval(int level) const
        // ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) ->
        //     ncmul(...,x1,x2,...,x3,x4,...)  (associativity)
        size_t factors = 0;
-       exvector::const_iterator cit = evaledseq.begin(), citend = evaledseq.end();
-       while (cit != citend)
-               factors += count_factors(*cit++);
+       for (auto & it : evaledseq)
+               factors += count_factors(it);
        
        exvector assocseq;
        assocseq.reserve(factors);
-       cit = evaledseq.begin();
        make_flat_inserter mf(evaledseq, true);
-       while (cit != citend)
-       {       ex factor = mf.handle_factor(*(cit++), 1);
+       for (auto & it : evaledseq) {
+               ex factor = mf.handle_factor(it, 1);
                append_factors(assocseq, factor);
        }
        
@@ -344,9 +331,8 @@ ex ncmul::eval(int level) const
        size_t count_commutative=0;
        size_t count_noncommutative=0;
        size_t count_noncommutative_composite=0;
-       cit = assocseq.begin(); citend = assocseq.end();
-       while (cit != citend) {
-               rettypes[i] = cit->return_type();
+       for (auto & it : assocseq) {
+               rettypes[i] = it.return_type();
                switch (rettypes[i]) {
                case return_types::commutative:
                        count_commutative++;
@@ -360,7 +346,7 @@ ex ncmul::eval(int level) const
                default:
                        throw(std::logic_error("ncmul::eval(): invalid return type"));
                }
-               ++i; ++cit;
+               ++i;
        }
        GINAC_ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size());
 
@@ -396,14 +382,13 @@ ex ncmul::eval(int level) const
                evv.reserve(assoc_num);
                rttinfos.reserve(assoc_num);
 
-               cit = assocseq.begin(), citend = assocseq.end();
-               while (cit != citend) {
-                       return_type_t ti = cit->return_type_tinfo();
+               for (auto & it : assocseq) {
+                       return_type_t ti = it.return_type_tinfo();
                        size_t rtt_num = rttinfos.size();
                        // search type in vector of known types
                        for (i=0; i<rtt_num; ++i) {
                                if(ti == rttinfos[i]) {
-                                       evv[i].push_back(*cit);
+                                       evv[i].push_back(it);
                                        break;
                                }
                        }
@@ -412,9 +397,8 @@ ex ncmul::eval(int level) const
                                rttinfos.push_back(ti);
                                evv.push_back(exvector());
                                (evv.end()-1)->reserve(assoc_num);
-                               (evv.end()-1)->push_back(*cit);
+                               (evv.end()-1)->push_back(it);
                        }
-                       ++cit;
                }
 
                size_t evv_num = evv.size();
@@ -449,14 +433,11 @@ ex ncmul::evalm() const
        // Evaluate children first
        exvector s;
        s.reserve(seq.size());
-       exvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               s.push_back(it->evalm());
-               it++;
-       }
+       for (auto & it : seq)
+               s.push_back(it.evalm());
 
        // If there are only matrices, simply multiply them
-       it = s.begin(); itend = s.end();
+       auto it = s.begin(), itend = s.end();
        if (is_a<matrix>(*it)) {
                matrix prod(ex_to<matrix>(*it));
                it++;
@@ -495,11 +476,11 @@ ex ncmul::conjugate() const
 
        exvector ev;
        ev.reserve(nops());
-       for (const_iterator i=end(); i!=begin();) {
+       for (auto i=end(); i!=begin();) {
                --i;
                ev.push_back(i->conjugate());
        }
-       return (new ncmul(ev, true))->setflag(status_flags::dynallocated).eval();
+       return (new ncmul(std::move(ev), true))->setflag(status_flags::dynallocated).eval();
 }
 
 ex ncmul::real_part() const
@@ -575,12 +556,9 @@ return_type_t ncmul::return_type_tinfo() const
                return make_return_type_t<ncmul>();
 
        // return type_info of first noncommutative element
-       exvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               if (i->return_type() == return_types::noncommutative)
-                       return i->return_type_tinfo();
-               ++i;
-       }
+       for (auto & i : seq)
+               if (i.return_type() == return_types::noncommutative)
+                       return i.return_type_tinfo();
 
        // no noncommutative element found, should not happen
        return make_return_type_t<ncmul>();
@@ -598,7 +576,7 @@ return_type_t ncmul::return_type_tinfo() const
 
 exvector ncmul::expandchildren(unsigned options) const
 {
-       const_iterator cit = this->seq.begin(), end = this->seq.end();
+       auto cit = this->seq.begin(), end = this->seq.end();
        while (cit != end) {
                const ex & expanded_ex = cit->expand(options);
                if (!are_ex_trivially_equal(*cit, expanded_ex)) {
index 6870b77f4b7c8b589d05a1ceafd842cfadb82e88..e0920b36efdbc6dd8a8d3ab37212bae34c27584e 100644 (file)
@@ -157,12 +157,10 @@ typedef std::vector<sym_desc> sym_desc_vec;
 // Add symbol the sym_desc_vec (used internally by get_symbol_stats())
 static void add_symbol(const ex &s, sym_desc_vec &v)
 {
-       sym_desc_vec::const_iterator it = v.begin(), itend = v.end();
-       while (it != itend) {
-               if (it->sym.is_equal(s))  // If it's already in there, don't add it a second time
+       for (auto & it : v)
+               if (it.sym.is_equal(s))  // If it's already in there, don't add it a second time
                        return;
-               ++it;
-       }
+
        sym_desc d;
        d.sym = s;
        v.push_back(d);
@@ -197,17 +195,15 @@ static void get_symbol_stats(const ex &a, const ex &b, sym_desc_vec &v)
 {
        collect_symbols(a.eval(), v);   // eval() to expand assigned symbols
        collect_symbols(b.eval(), v);
-       sym_desc_vec::iterator it = v.begin(), itend = v.end();
-       while (it != itend) {
-               int deg_a = a.degree(it->sym);
-               int deg_b = b.degree(it->sym);
-               it->deg_a = deg_a;
-               it->deg_b = deg_b;
-               it->max_deg = std::max(deg_a, deg_b);
-               it->max_lcnops = std::max(a.lcoeff(it->sym).nops(), b.lcoeff(it->sym).nops());
-               it->ldeg_a = a.ldegree(it->sym);
-               it->ldeg_b = b.ldegree(it->sym);
-               ++it;
+       for (auto & it : v) {
+               int deg_a = a.degree(it.sym);
+               int deg_b = b.degree(it.sym);
+               it.deg_a = deg_a;
+               it.deg_b = deg_b;
+               it.max_deg = std::max(deg_a, deg_b);
+               it.max_lcnops = std::max(a.lcoeff(it.sym).nops(), b.lcoeff(it.sym).nops());
+               it.ldeg_a = a.ldegree(it.sym);
+               it.ldeg_b = b.ldegree(it.sym);
        }
        std::sort(v.begin(), v.end());
 
@@ -321,15 +317,12 @@ numeric numeric::integer_content() const
 
 numeric add::integer_content() const
 {
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
        numeric c = *_num0_p, l = *_num1_p;
-       while (it != itend) {
-               GINAC_ASSERT(!is_exactly_a<numeric>(it->rest));
-               GINAC_ASSERT(is_exactly_a<numeric>(it->coeff));
-               c = gcd(ex_to<numeric>(it->coeff).numer(), c);
-               l = lcm(ex_to<numeric>(it->coeff).denom(), l);
-               it++;
+       for (auto & it : seq) {
+               GINAC_ASSERT(!is_exactly_a<numeric>(it.rest));
+               GINAC_ASSERT(is_exactly_a<numeric>(it.coeff));
+               c = gcd(ex_to<numeric>(it.coeff).numer(), c);
+               l = lcm(ex_to<numeric>(it.coeff).denom(), l);
        }
        GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
        c = gcd(ex_to<numeric>(overall_coeff).numer(), c);
@@ -340,11 +333,8 @@ numeric add::integer_content() const
 numeric mul::integer_content() const
 {
 #ifdef DO_GINAC_ASSERT
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
-       while (it != itend) {
-               GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(*it)));
-               ++it;
+       for (auto & it : seq) {
+               GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(it)));
        }
 #endif // def DO_GINAC_ASSERT
        GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
@@ -796,10 +786,10 @@ static bool divide_in_z(const ex &a, const ex &b, ex &q, sym_desc_vec::const_ite
 
        if (is_exactly_a<mul>(b)) {
                ex qbar = a;
-               for (const_iterator itrb = b.begin(); itrb != b.end(); ++itrb) {
+               for (const auto & it : b) {
                        sym_desc_vec sym_stats;
-                       get_symbol_stats(a, *itrb, sym_stats);
-                       if (!divide_in_z(qbar, *itrb, q, sym_stats.begin()))
+                       get_symbol_stats(a, it, sym_stats);
+                       if (!divide_in_z(qbar, it, q, sym_stats.begin()))
                                return false;
 
                        qbar = q;
@@ -1165,17 +1155,14 @@ numeric numeric::max_coefficient() const
 
 numeric add::max_coefficient() const
 {
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
        GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
        numeric cur_max = abs(ex_to<numeric>(overall_coeff));
-       while (it != itend) {
+       for (auto & it : seq) {
                numeric a;
-               GINAC_ASSERT(!is_exactly_a<numeric>(it->rest));
-               a = abs(ex_to<numeric>(it->coeff));
+               GINAC_ASSERT(!is_exactly_a<numeric>(it.rest));
+               a = abs(ex_to<numeric>(it.coeff));
                if (a > cur_max)
                        cur_max = a;
-               it++;
        }
        return cur_max;
 }
@@ -1183,11 +1170,8 @@ numeric add::max_coefficient() const
 numeric mul::max_coefficient() const
 {
 #ifdef DO_GINAC_ASSERT
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
-       while (it != itend) {
-               GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(*it)));
-               it++;
+       for (auto & it : seq) {
+               GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(it)));
        }
 #endif // def DO_GINAC_ASSERT
        GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
@@ -1215,14 +1199,11 @@ ex add::smod(const numeric &xi) const
 {
        epvector newseq;
        newseq.reserve(seq.size()+1);
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
-       while (it != itend) {
-               GINAC_ASSERT(!is_exactly_a<numeric>(it->rest));
-               numeric coeff = GiNaC::smod(ex_to<numeric>(it->coeff), xi);
+       for (auto & it : seq) {
+               GINAC_ASSERT(!is_exactly_a<numeric>(it.rest));
+               numeric coeff = GiNaC::smod(ex_to<numeric>(it.coeff), xi);
                if (!coeff.is_zero())
-                       newseq.push_back(expair(it->rest, coeff));
-               it++;
+                       newseq.push_back(expair(it.rest, coeff));
        }
        GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
        numeric coeff = GiNaC::smod(ex_to<numeric>(overall_coeff), xi);
@@ -1232,11 +1213,8 @@ ex add::smod(const numeric &xi) const
 ex mul::smod(const numeric &xi) const
 {
 #ifdef DO_GINAC_ASSERT
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
-       while (it != itend) {
-               GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(*it)));
-               it++;
+       for (auto & it : seq) {
+               GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(it)));
        }
 #endif // def DO_GINAC_ASSERT
        mul * mulcopyp = new mul(*this);
@@ -1863,11 +1841,8 @@ ex sqrfree(const ex &a, const lst &l)
        if (l.nops()==0) {
                sym_desc_vec sdv;
                get_symbol_stats(a, _ex0, sdv);
-               sym_desc_vec::const_iterator it = sdv.begin(), itend = sdv.end();
-               while (it != itend) {
-                       args.append(it->sym);
-                       ++it;
-               }
+               for (auto & it : sdv)
+                       args.append(it.sym);
        } else {
                args = l;
        }
@@ -1890,18 +1865,15 @@ ex sqrfree(const ex &a, const lst &l)
 
        // recurse down the factors in remaining variables
        if (newargs.nops()>0) {
-               exvector::iterator i = factors.begin();
-               while (i != factors.end()) {
-                       *i = sqrfree(*i, newargs);
-                       ++i;
-               }
+               for (auto & it : factors)
+                       it = sqrfree(it, newargs);
        }
 
        // Done with recursion, now construct the final result
        ex result = _ex1;
-       exvector::const_iterator it = factors.begin(), itend = factors.end();
-       for (int p = 1; it!=itend; ++it, ++p)
-               result *= power(*it, p);
+       int p = 1;
+       for (auto & it : factors)
+               result *= power(it, p++);
 
        // Yun's algorithm does not account for constant factors.  (For univariate
        // polynomials it works only in the monic case.)  We can correct this by
@@ -2010,7 +1982,7 @@ static ex replace_with_symbol(const ex & e, exmap & repl, exmap & rev_lookup)
        ex e_replaced = e.subs(repl, subs_options::no_pattern);
 
        // Expression already replaced? Then return the assigned symbol
-       exmap::const_iterator it = rev_lookup.find(e_replaced);
+       auto it = rev_lookup.find(e_replaced);
        if (it != rev_lookup.end())
                return it->second;
 
@@ -2034,9 +2006,9 @@ static ex replace_with_symbol(const ex & e, exmap & repl)
        ex e_replaced = e.subs(repl, subs_options::no_pattern);
 
        // Expression already replaced? Then return the assigned symbol
-       for (exmap::const_iterator it = repl.begin(); it != repl.end(); ++it)
-               if (it->second.is_equal(e_replaced))
-                       return it->first;
+       for (auto & it : repl)
+               if (it.second.is_equal(e_replaced))
+                       return it.first;
 
        // Otherwise create new symbol and add to list, taking care that the
        // replacement expression doesn't itself contain symbols from repl,
@@ -2181,12 +2153,10 @@ ex add::normal(exmap & repl, exmap & rev_lookup, int level) const
        exvector nums, dens;
        nums.reserve(seq.size()+1);
        dens.reserve(seq.size()+1);
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               ex n = ex_to<basic>(recombine_pair_to_ex(*it)).normal(repl, rev_lookup, level-1);
+       for (auto & it : seq) {
+               ex n = ex_to<basic>(recombine_pair_to_ex(it)).normal(repl, rev_lookup, level-1);
                nums.push_back(n.op(0));
                dens.push_back(n.op(1));
-               it++;
        }
        ex n = ex_to<numeric>(overall_coeff).normal(repl, rev_lookup, level-1);
        nums.push_back(n.op(0));
@@ -2198,8 +2168,8 @@ ex add::normal(exmap & repl, exmap & rev_lookup, int level) const
 //std::clog << "add::normal uses " << nums.size() << " summands:\n";
 
        // Add fractions sequentially
-       exvector::const_iterator num_it = nums.begin(), num_itend = nums.end();
-       exvector::const_iterator den_it = dens.begin(), den_itend = dens.end();
+       auto num_it = nums.begin(), num_itend = nums.end();
+       auto den_it = dens.begin(), den_itend = dens.end();
 //std::clog << " num = " << *num_it << ", den = " << *den_it << std::endl;
        ex num = *num_it++, den = *den_it++;
        while (num_it != num_itend) {
@@ -2240,12 +2210,10 @@ ex mul::normal(exmap & repl, exmap & rev_lookup, int level) const
        exvector num; num.reserve(seq.size());
        exvector den; den.reserve(seq.size());
        ex n;
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               n = ex_to<basic>(recombine_pair_to_ex(*it)).normal(repl, rev_lookup, level-1);
+       for (auto & it : seq) {
+               n = ex_to<basic>(recombine_pair_to_ex(it)).normal(repl, rev_lookup, level-1);
                num.push_back(n.op(0));
                den.push_back(n.op(1));
-               it++;
        }
        n = ex_to<numeric>(overall_coeff).normal(repl, rev_lookup, level-1);
        num.push_back(n.op(0));
@@ -2319,14 +2287,12 @@ ex power::normal(exmap & repl, exmap & rev_lookup, int level) const
 ex pseries::normal(exmap & repl, exmap & rev_lookup, int level) const
 {
        epvector newseq;
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               ex restexp = i->rest.normal();
+       for (auto & it : seq) {
+               ex restexp = it.rest.normal();
                if (!restexp.is_zero())
-                       newseq.push_back(expair(restexp, i->coeff));
-               ++i;
+                       newseq.push_back(expair(restexp, it.coeff));
        }
-       ex n = pseries(relational(var,point), newseq);
+       ex n = pseries(relational(var,point), std::move(newseq));
        return (new lst(replace_with_symbol(n, repl, rev_lookup), _ex1))->setflag(status_flags::dynallocated);
 }
 
@@ -2442,15 +2408,15 @@ ex ex::to_rational(lst & repl_lst) const
 {
        // Convert lst to exmap
        exmap m;
-       for (lst::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it)
-               m.insert(std::make_pair(it->op(0), it->op(1)));
+       for (auto & it : repl_lst)
+               m.insert(std::make_pair(it.op(0), it.op(1)));
 
        ex ret = bp->to_rational(m);
 
        // Convert exmap back to lst
        repl_lst.remove_all();
-       for (exmap::const_iterator it = m.begin(); it != m.end(); ++it)
-               repl_lst.append(it->first == it->second);
+       for (auto & it : m)
+               repl_lst.append(it.first == it.second);
 
        return ret;
 }
@@ -2465,15 +2431,15 @@ ex ex::to_polynomial(lst & repl_lst) const
 {
        // Convert lst to exmap
        exmap m;
-       for (lst::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it)
-               m.insert(std::make_pair(it->op(0), it->op(1)));
+       for (auto & it : repl_lst)
+               m.insert(std::make_pair(it.op(0), it.op(1)));
 
        ex ret = bp->to_polynomial(m);
 
        // Convert exmap back to lst
        repl_lst.remove_all();
-       for (exmap::const_iterator it = m.begin(); it != m.end(); ++it)
-               repl_lst.append(it->first == it->second);
+       for (auto & it : m)
+               repl_lst.append(it.first == it.second);
 
        return ret;
 }
@@ -2580,11 +2546,9 @@ ex expairseq::to_rational(exmap & repl) const
 {
        epvector s;
        s.reserve(seq.size());
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               s.push_back(split_ex_to_pair(recombine_pair_to_ex(*i).to_rational(repl)));
-               ++i;
-       }
+       for (auto & it : seq)
+               s.push_back(split_ex_to_pair(recombine_pair_to_ex(it).to_rational(repl)));
+
        ex oc = overall_coeff.to_rational(repl);
        if (oc.info(info_flags::numeric))
                return thisexpairseq(std::move(s), overall_coeff);
@@ -2598,11 +2562,9 @@ ex expairseq::to_polynomial(exmap & repl) const
 {
        epvector s;
        s.reserve(seq.size());
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               s.push_back(split_ex_to_pair(recombine_pair_to_ex(*i).to_polynomial(repl)));
-               ++i;
-       }
+       for (auto & it : seq)
+               s.push_back(split_ex_to_pair(recombine_pair_to_ex(it).to_polynomial(repl)));
+
        ex oc = overall_coeff.to_polynomial(repl);
        if (oc.info(info_flags::numeric))
                return thisexpairseq(std::move(s), overall_coeff);
index 9c70b46e7fba72adee830c9284ef90de8ff42153..2102e94b6086e4ce146bbb7d9ea8731a5f31a97f 100644 (file)
@@ -2539,9 +2539,8 @@ _numeric_digits& _numeric_digits::operator=(long prec)
        cln::default_float_format = cln::float_format(prec);
 
        // call registered callbacks
-       std::vector<digits_changed_callback>::const_iterator it = callbacklist.begin(), end = callbacklist.end();
-       for (; it != end; ++it) {
-               (*it)(digitsdiff);
+       for (auto it : callbacklist) {
+               (it)(digitsdiff);
        }
 
        return *this;
index f0beedea43544929c17f471475e83d1bf8e1e197..e3dc177930dee06714624db38f6d1e07cec1a858 100644 (file)
@@ -96,13 +96,9 @@ const prototype_table& get_default_reader()
                reader[make_pair("pow", 2)] = pow_reader;
                reader[make_pair("power", 2)] = power_reader;
                reader[make_pair("lst", 0)] = lst_reader;
-               std::vector<function_options>::const_iterator it =
-                       registered_functions_hack::get_registered_functions().begin();
-               std::vector<function_options>::const_iterator end =
-                       registered_functions_hack::get_registered_functions().end();
                unsigned serial = 0;
-               for (; it != end; ++it) {
-                       prototype proto = make_pair(it->get_name(), it->get_nparams());
+               for (auto & it : registered_functions_hack::get_registered_functions()) {
+                       prototype proto = make_pair(it.get_name(), it.get_nparams());
                        reader[proto] = encode_serial_as_reader_func(serial);
                        ++serial;
                }
index ce502c1f09d6a4fe2b6872a7e61995f9daea064b..c06b16ebb625363f39a69cf406c93dce574f86d2 100644 (file)
@@ -139,8 +139,8 @@ static void wipe_out_zeros(ex_collect_priv_t& m)
        }
 }
 
-GiNaC::ex
-ex_collect_to_ex(const ex_collect_t& ec, const GiNaC::exvector& vars)
+ex
+ex_collect_to_ex(const ex_collect_t& ec, const exvector& vars)
 {
        exvector ev;
        ev.reserve(ec.size());
index 09014e3dc25832d1281bd926fd665e134b7cc035..f2e557111666a9c5203e7c850924c784fd3b746d 100644 (file)
@@ -37,7 +37,7 @@ typedef std::vector<int> exp_vector_t;
 static inline bool operator<(const exp_vector_t& v1, const exp_vector_t& v2)
 {
        return std::lexicographical_compare(v1.rbegin(), v1.rend(),
-                                           v2.rbegin(), v2.rend());
+                                           v2.rbegin(), v2.rend());
 }
 
 static inline bool operator>(const exp_vector_t& v1, const exp_vector_t& v2)
@@ -49,8 +49,8 @@ static inline bool operator>(const exp_vector_t& v1, const exp_vector_t& v2)
 
 static inline bool zerop(const exp_vector_t& v)
 {
-       for (exp_vector_t::const_reverse_iterator i = v.rbegin(); i != v.rend(); ++i) {
-               if (*i != 0) 
+       for (auto & i : v) {
+               if (i != 0)
                        return false;
        }
        return true;
index 24daea4884ecd9eb2400da24032e7c6df7671caf..09b9590b07de3eb5ee97cae3a8f9040f10fccf70 100644 (file)
@@ -83,11 +83,9 @@ typedef std::vector<sym_desc> sym_desc_vec;
 // Add symbol the sym_desc_vec (used internally by get_symbol_stats())
 static void add_symbol(const ex &s, sym_desc_vec &v)
 {
-       sym_desc_vec::const_iterator it = v.begin(), itend = v.end();
-       while (it != itend) {
-               if (it->sym.is_equal(s))  // If it's already in there, don't add it a second time
+       for (auto & it : v) {
+               if (it.sym.is_equal(s))  // If it's already in there, don't add it a second time
                        return;
-               ++it;
        }
        sym_desc d;
        d.sym = s;
@@ -123,17 +121,15 @@ static void get_symbol_stats(const ex &a, const ex &b, sym_desc_vec &v)
 {
        collect_symbols(a, v);
        collect_symbols(b, v);
-       sym_desc_vec::iterator it = v.begin(), itend = v.end();
-       while (it != itend) {
-               int deg_a = a.degree(it->sym);
-               int deg_b = b.degree(it->sym);
-               it->deg_a = deg_a;
-               it->deg_b = deg_b;
-               it->max_deg = std::max(deg_a, deg_b);
-               it->max_lcnops = std::max(a.lcoeff(it->sym).nops(), b.lcoeff(it->sym).nops());
-               it->ldeg_a = a.ldegree(it->sym);
-               it->ldeg_b = b.ldegree(it->sym);
-               ++it;
+       for (auto & it : v) {
+               int deg_a = a.degree(it.sym);
+               int deg_b = b.degree(it.sym);
+               it.deg_a = deg_a;
+               it.deg_b = deg_b;
+               it.max_deg = std::max(deg_a, deg_b);
+               it.max_lcnops = std::max(a.lcoeff(it.sym).nops(), b.lcoeff(it.sym).nops());
+               it.ldeg_a = a.ldegree(it.sym);
+               it.ldeg_b = b.ldegree(it.sym);
        }
        std::sort(v.begin(), v.end());
 }
index 2106b5113c6e26a5c60ebdb57c10991d661a4572..f951e4fdbafdea30eb10df0102c29b8fffdf4bfe 100644 (file)
@@ -524,8 +524,8 @@ ex power::eval(int level) const
                                addp->setflag(status_flags::dynallocated);
                                addp->clearflag(status_flags::hash_calculated);
                                addp->overall_coeff = ex_to<numeric>(addp->overall_coeff).div_dyn(icont);
-                               for (epvector::iterator i = addp->seq.begin(); i != addp->seq.end(); ++i)
-                                       i->coeff = ex_to<numeric>(i->coeff).div_dyn(icont);
+                               for (auto & i : addp->seq)
+                                       i.coeff = ex_to<numeric>(i.coeff).div_dyn(icont);
 
                                const numeric c = icont.power(*num_exponent);
                                if (likely(c != *_num1_p))
@@ -653,12 +653,12 @@ ex power::subs(const exmap & m, unsigned options) const
        if (!(options & subs_options::algebraic))
                return subs_one_level(m, options);
 
-       for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
+       for (auto & it : m) {
                int nummatches = std::numeric_limits<int>::max();
                exmap repls;
-               if (tryfactsubs(*this, it->first, nummatches, repls)) {
-                       ex anum = it->second.subs(repls, subs_options::no_pattern);
-                       ex aden = it->first.subs(repls, subs_options::no_pattern);
+               if (tryfactsubs(*this, it.first, nummatches, repls)) {
+                       ex anum = it.second.subs(repls, subs_options::no_pattern);
+                       ex aden = it.first.subs(repls, subs_options::no_pattern);
                        ex result = (*this)*power(anum/aden, nummatches);
                        return (ex_to<basic>(result)).subs_one_level(m, options);
                }
@@ -802,21 +802,18 @@ ex power::expand(unsigned options) const
                epvector powseq;
                prodseq.reserve(m.seq.size() + 1);
                powseq.reserve(m.seq.size() + 1);
-               epvector::const_iterator last = m.seq.end();
-               epvector::const_iterator cit = m.seq.begin();
                bool possign = true;
 
                // search for positive/negative factors
-               while (cit!=last) {
-                       ex e=m.recombine_pair_to_ex(*cit);
+               for (auto & cit : m.seq) {
+                       ex e=m.recombine_pair_to_ex(cit);
                        if (e.info(info_flags::positive))
                                prodseq.push_back(pow(e, exponent).expand(options));
                        else if (e.info(info_flags::negative)) {
                                prodseq.push_back(pow(-e, exponent).expand(options));
                                possign = !possign;
                        } else
-                               powseq.push_back(*cit);
-                       ++cit;
+                               powseq.push_back(cit);
                }
 
                // take care on the numeric coefficient
@@ -847,11 +844,8 @@ ex power::expand(unsigned options) const
                const add &a = ex_to<add>(expanded_exponent);
                exvector distrseq;
                distrseq.reserve(a.seq.size() + 1);
-               epvector::const_iterator last = a.seq.end();
-               epvector::const_iterator cit = a.seq.begin();
-               while (cit!=last) {
-                       distrseq.push_back(power(expanded_basis, a.recombine_pair_to_ex(*cit)));
-                       ++cit;
+               for (auto & cit : a.seq) {
+                       distrseq.push_back(power(expanded_basis, a.recombine_pair_to_ex(cit)));
                }
                
                // Make sure that e.g. (x+y)^(2+a) expands the (x+y)^2 factor
@@ -1006,8 +1000,8 @@ private:
                element *head, *i, *after_i;
                // NB: Partition must be sorted in non-decreasing order.
                explicit coolmulti(const std::vector<int>& partition)
+                 : head(nullptr), i(nullptr), after_i(nullptr)
                {
-                       head = nullptr;
                        for (unsigned n = 0; n < partition.size(); ++n) {
                                head = new element(partition[n], head);
                                if (n <= 1)
@@ -1080,11 +1074,9 @@ const numeric
 multinomial_coefficient(const std::vector<int> p)
 {
        numeric n = 0, d = 1;
-       std::vector<int>::const_iterator it = p.begin(), itend = p.end();
-       while (it != itend) {
-               n += numeric(*it);
-               d *= factorial(numeric(*it));
-               ++it;
+       for (auto & it : p) {
+               n += numeric(it);
+               d *= factorial(numeric(it));
        }
        return factorial(numeric(n)) / d;
 }
@@ -1327,17 +1319,14 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr
        distrseq.reserve(m.seq.size());
        bool need_reexpand = false;
 
-       epvector::const_iterator last = m.seq.end();
-       epvector::const_iterator cit = m.seq.begin();
-       while (cit!=last) {
-               expair p = m.combine_pair_with_coeff_to_pair(*cit, n);
-               if (from_expand && is_exactly_a<add>(cit->rest) && ex_to<numeric>(p.coeff).is_pos_integer()) {
+       for (auto & cit : m.seq) {
+               expair p = m.combine_pair_with_coeff_to_pair(cit, n);
+               if (from_expand && is_exactly_a<add>(cit.rest) && ex_to<numeric>(p.coeff).is_pos_integer()) {
                        // this happens when e.g. (a+b)^(1/2) gets squared and
                        // the resulting product needs to be reexpanded
                        need_reexpand = true;
                }
                distrseq.push_back(p);
-               ++cit;
        }
 
        const mul & result = static_cast<const mul &>((new mul(distrseq, ex_to<numeric>(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated));
index e50af5150ff22eb0ecd3ac7310ba0501c4552cad..2ae10f4f73a3150e9f6fcfc5373fd8afecc2fd29 100644 (file)
@@ -84,12 +84,12 @@ pseries::pseries(const ex &rel_, const epvector &ops_) : seq(ops_)
 void pseries::read_archive(const archive_node &n, lst &sym_lst) 
 {
        inherited::read_archive(n, sym_lst);
-       archive_node::archive_node_cit first = n.find_first("coeff");
-       archive_node::archive_node_cit last = n.find_last("power");
+       auto first = n.find_first("coeff");
+       auto last = n.find_last("power");
        ++last;
        seq.reserve((last-first)/2);
 
-       for (archive_node::archive_node_cit loc = first; loc < last;) {
+       for (auto loc = first; loc < last;) {
                ex rest;
                ex coeff;
                n.find_ex_by_loc(loc++, rest, sym_lst);
@@ -104,11 +104,9 @@ void pseries::read_archive(const archive_node &n, lst &sym_lst)
 void pseries::archive(archive_node &n) const
 {
        inherited::archive(n);
-       epvector::const_iterator i = seq.begin(), iend = seq.end();
-       while (i != iend) {
-               n.add_ex("coeff", i->rest);
-               n.add_ex("power", i->coeff);
-               ++i;
+       for (auto & it : seq) {
+               n.add_ex("coeff", it.rest);
+               n.add_ex("power", it.coeff);
        }
        n.add_ex("var", var);
        n.add_ex("point", point);
@@ -129,7 +127,7 @@ void pseries::print_series(const print_context & c, const char *openbrace, const
        if (seq.empty())
                c.s << '0';
 
-       epvector::const_iterator i = seq.begin(), end = seq.end();
+       auto i = seq.begin(), end = seq.end();
        while (i != end) {
 
                // print a sign, if needed
@@ -393,7 +391,7 @@ ex pseries::eval(int level) const
                new_seq.push_back(expair(it->rest.eval(level-1), it->coeff));
                ++it;
        }
-       return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
+       return (new pseries(relational(var,point), std::move(new_seq)))->setflag(status_flags::dynallocated | status_flags::evaluated);
 }
 
 /** Evaluate coefficients numerically. */
@@ -413,7 +411,7 @@ ex pseries::evalf(int level) const
                new_seq.push_back(expair(it->rest.evalf(level-1), it->coeff));
                ++it;
        }
-       return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
+       return (new pseries(relational(var,point), std::move(new_seq)))->setflag(status_flags::dynallocated | status_flags::evaluated);
 }
 
 ex pseries::conjugate() const
@@ -421,16 +419,14 @@ ex pseries::conjugate() const
        if(!var.info(info_flags::real))
                return conjugate_function(*this).hold();
 
-       epvector * newseq = conjugateepvector(seq);
+       std::unique_ptr<epvector> newseq(conjugateepvector(seq));
        ex newpoint = point.conjugate();
 
        if (!newseq && are_ex_trivially_equal(point, newpoint)) {
                return *this;
        }
 
-       ex result = (new pseries(var==newpoint, newseq ? *newseq : seq))->setflag(status_flags::dynallocated);
-       delete newseq;
-       return result;
+       return (new pseries(var==newpoint, newseq ? std::move(*newseq) : seq))->setflag(status_flags::dynallocated);
 }
 
 ex pseries::real_part() const
@@ -443,9 +439,9 @@ ex pseries::real_part() const
 
        epvector v;
        v.reserve(seq.size());
-       for(epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
-               v.push_back(expair((i->rest).real_part(), i->coeff));
-       return (new pseries(var==point, v))->setflag(status_flags::dynallocated);
+       for (auto & it : seq)
+               v.push_back(expair((it.rest).real_part(), it.coeff));
+       return (new pseries(var==point, std::move(v)))->setflag(status_flags::dynallocated);
 }
 
 ex pseries::imag_part() const
@@ -458,15 +454,15 @@ ex pseries::imag_part() const
 
        epvector v;
        v.reserve(seq.size());
-       for(epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
-               v.push_back(expair((i->rest).imag_part(), i->coeff));
-       return (new pseries(var==point, v))->setflag(status_flags::dynallocated);
+       for (auto & it : seq)
+               v.push_back(expair((it.rest).imag_part(), it.coeff));
+       return (new pseries(var==point, std::move(v)))->setflag(status_flags::dynallocated);
 }
 
 ex pseries::eval_integ() const
 {
        epvector *newseq = nullptr;
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+       for (auto i=seq.begin(); i!=seq.end(); ++i) {
                if (newseq) {
                        newseq->push_back(expair(i->rest.eval_integ(), i->coeff));
                        continue;
@@ -475,7 +471,7 @@ ex pseries::eval_integ() const
                if (!are_ex_trivially_equal(newterm, i->rest)) {
                        newseq = new epvector;
                        newseq->reserve(seq.size());
-                       for (epvector::const_iterator j=seq.begin(); j!=i; ++j)
+                       for (auto j=seq.begin(); j!=i; ++j)
                                newseq->push_back(*j);
                        newseq->push_back(expair(newterm, i->coeff));
                }
@@ -493,7 +489,7 @@ ex pseries::evalm() const
        // evalm each coefficient
        epvector newseq;
        bool something_changed = false;
-       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+       for (auto i=seq.begin(); i!=seq.end(); ++i) {
                if (something_changed) {
                        ex newcoeff = i->rest.evalm();
                        if (!newcoeff.is_zero())
@@ -511,7 +507,7 @@ ex pseries::evalm() const
                }
        }
        if (something_changed)
-               return (new pseries(var==point, newseq))->setflag(status_flags::dynallocated);
+               return (new pseries(var==point, std::move(newseq)))->setflag(status_flags::dynallocated);
        else
                return *this;
 }
@@ -528,11 +524,8 @@ ex pseries::subs(const exmap & m, unsigned options) const
        // expansion point
        epvector newseq;
        newseq.reserve(seq.size());
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               newseq.push_back(expair(it->rest.subs(m, options), it->coeff));
-               ++it;
-       }
+       for (auto & it : seq)
+               newseq.push_back(expair(it.rest.subs(m, options), it.coeff));
        return (new pseries(relational(var,point.subs(m, options)), newseq))->setflag(status_flags::dynallocated);
 }
 
@@ -541,14 +534,12 @@ ex pseries::subs(const exmap & m, unsigned options) const
 ex pseries::expand(unsigned options) const
 {
        epvector newseq;
-       epvector::const_iterator i = seq.begin(), end = seq.end();
-       while (i != end) {
-               ex restexp = i->rest.expand();
+       for (auto & it : seq) {
+               ex restexp = it.rest.expand();
                if (!restexp.is_zero())
-                       newseq.push_back(expair(restexp, i->coeff));
-               ++i;
+                       newseq.push_back(expair(restexp, it.coeff));
        }
-       return (new pseries(relational(var,point), newseq))
+       return (new pseries(relational(var,point), std::move(newseq)))
                ->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
 }
 
@@ -557,51 +548,45 @@ ex pseries::expand(unsigned options) const
 ex pseries::derivative(const symbol & s) const
 {
        epvector new_seq;
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
 
        if (s == var) {
                
                // FIXME: coeff might depend on var
-               while (it != itend) {
-                       if (is_order_function(it->rest)) {
-                               new_seq.push_back(expair(it->rest, it->coeff - 1));
+               for (auto & it : seq) {
+                       if (is_order_function(it.rest)) {
+                               new_seq.push_back(expair(it.rest, it.coeff - 1));
                        } else {
-                               ex c = it->rest * it->coeff;
+                               ex c = it.rest * it.coeff;
                                if (!c.is_zero())
-                                       new_seq.push_back(expair(c, it->coeff - 1));
+                                       new_seq.push_back(expair(c, it.coeff - 1));
                        }
-                       ++it;
                }
 
        } else {
 
-               while (it != itend) {
-                       if (is_order_function(it->rest)) {
-                               new_seq.push_back(*it);
+               for (auto & it : seq) {
+                       if (is_order_function(it.rest)) {
+                               new_seq.push_back(it);
                        } else {
-                               ex c = it->rest.diff(s);
+                               ex c = it.rest.diff(s);
                                if (!c.is_zero())
-                                       new_seq.push_back(expair(c, it->coeff));
+                                       new_seq.push_back(expair(c, it.coeff));
                        }
-                       ++it;
                }
        }
 
-       return pseries(relational(var,point), new_seq);
+       return pseries(relational(var,point), std::move(new_seq));
 }
 
 ex pseries::convert_to_poly(bool no_order) const
 {
        ex e;
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       
-       while (it != itend) {
-               if (is_order_function(it->rest)) {
+       for (auto & it : seq) {
+               if (is_order_function(it.rest)) {
                        if (!no_order)
-                               e += Order(power(var - point, it->coeff));
+                               e += Order(power(var - point, it.coeff));
                } else
-                       e += it->rest * power(var - point, it->coeff);
-               ++it;
+                       e += it.rest * power(var - point, it.coeff);
        }
        return e;
 }
@@ -613,7 +598,7 @@ bool pseries::is_terminating() const
 
 ex pseries::coeffop(size_t i) const
 {
-       if (i >=nops())
+       if (i >= nops())
                throw (std::out_of_range("coeffop() out of range"));
        return seq[i].rest;
 }
@@ -713,10 +698,8 @@ ex pseries::add_series(const pseries &other) const
        
        // Series addition
        epvector new_seq;
-       epvector::const_iterator a = seq.begin();
-       epvector::const_iterator b = other.seq.begin();
-       epvector::const_iterator a_end = seq.end();
-       epvector::const_iterator b_end = other.seq.end();
+       auto a = seq.begin(), a_end = seq.end();
+       auto b = other.seq.begin(), b_end = other.seq.end();
        int pow_a = std::numeric_limits<int>::max(), pow_b = std::numeric_limits<int>::max();
        for (;;) {
                // If a is empty, fill up with elements from b and stop
@@ -766,7 +749,7 @@ ex pseries::add_series(const pseries &other) const
                        }
                }
        }
-       return pseries(relational(var,point), new_seq);
+       return pseries(relational(var,point), std::move(new_seq));
 }
 
 
@@ -781,16 +764,14 @@ ex add::series(const relational & r, int order, unsigned options) const
        acc = overall_coeff.series(r, order, options);
        
        // Add remaining terms
-       epvector::const_iterator it = seq.begin();
-       epvector::const_iterator itend = seq.end();
-       for (; it!=itend; ++it) {
+       for (auto & it : seq) {
                ex op;
-               if (is_exactly_a<pseries>(it->rest))
-                       op = it->rest;
+               if (is_exactly_a<pseries>(it.rest))
+                       op = it.rest;
                else
-                       op = it->rest.series(r, order, options);
-               if (!it->coeff.is_equal(_ex1))
-                       op = ex_to<pseries>(op).mul_const(ex_to<numeric>(it->coeff));
+                       op = it.rest.series(r, order, options);
+               if (!it.coeff.is_equal(_ex1))
+                       op = ex_to<pseries>(op).mul_const(ex_to<numeric>(it.coeff));
                
                // Series addition
                acc = ex_to<pseries>(acc).add_series(ex_to<pseries>(op));
@@ -809,13 +790,11 @@ ex pseries::mul_const(const numeric &other) const
        epvector new_seq;
        new_seq.reserve(seq.size());
        
-       epvector::const_iterator it = seq.begin(), itend = seq.end();
-       while (it != itend) {
-               if (!is_order_function(it->rest))
-                       new_seq.push_back(expair(it->rest * other, it->coeff));
+       for (auto & it : seq) {
+               if (!is_order_function(it.rest))
+                       new_seq.push_back(expair(it.rest * other, it.coeff));
                else
-                       new_seq.push_back(*it);
-               ++it;
+                       new_seq.push_back(it);
        }
        return pseries(relational(var,point), new_seq);
 }
@@ -893,20 +872,18 @@ ex mul::series(const relational & r, int order, unsigned options) const
        std::vector<bool> ldegree_redo;
 
        // find minimal degrees
-       const epvector::const_iterator itbeg = seq.begin();
-       const epvector::const_iterator itend = seq.end();
        // first round: obtain a bound up to which minimal degrees have to be
        // considered
-       for (epvector::const_iterator it=itbeg; it!=itend; ++it) {
+       for (auto & it : seq) {
 
-               ex expon = it->coeff;
+               ex expon = it.coeff;
                int factor = 1;
                ex buf;
                if (expon.info(info_flags::integer)) {
-                       buf = it->rest;
+                       buf = it.rest;
                        factor = ex_to<numeric>(expon).to_int();
                } else {
-                       buf = recombine_pair_to_ex(*it);
+                       buf = recombine_pair_to_ex(it);
                }
 
                int real_ldegree = 0;
@@ -943,16 +920,16 @@ ex mul::series(const relational & r, int order, unsigned options) const
        // method.
        // here we can ignore ldegrees larger than degbound
        size_t j = 0;
-       for (epvector::const_iterator it=itbeg; it!=itend; ++it) {
+       for (auto & it : seq) {
                if ( ldegree_redo[j] ) {
-                       ex expon = it->coeff;
+                       ex expon = it.coeff;
                        int factor = 1;
                        ex buf;
                        if (expon.info(info_flags::integer)) {
-                               buf = it->rest;
+                               buf = it.rest;
                                factor = ex_to<numeric>(expon).to_int();
                        } else {
-                               buf = recombine_pair_to_ex(*it);
+                               buf = recombine_pair_to_ex(it);
                        }
                        int real_ldegree = 0;
                        int orderloop = 0;
@@ -976,14 +953,14 @@ ex mul::series(const relational & r, int order, unsigned options) const
        }
 
        // Multiply with remaining terms
-       std::vector<int>::const_iterator itd = ldegrees.begin();
-       for (epvector::const_iterator it=itbeg; it!=itend; ++it, ++itd) {
+       auto itd = ldegrees.begin();
+       for (auto it=seq.begin(), itend=seq.end(); it!=itend; ++it, ++itd) {
 
                // do series expansion with adjusted order
                ex op = recombine_pair_to_ex(*it).series(r, order-degsum+(*itd), options);
 
                // Series multiplication
-               if (it == itbeg)
+               if (it == seq.begin())
                        acc = ex_to<pseries>(op);
                else
                        acc = ex_to<pseries>(acc.mul_series(ex_to<pseries>(op)));
@@ -1088,12 +1065,9 @@ ex pseries::power_const(const numeric &p, int deg) const
 pseries pseries::shift_exponents(int deg) const
 {
        epvector newseq = seq;
-       epvector::iterator i = newseq.begin(), end  = newseq.end();
-       while (i != end) {
-               i->coeff += deg;
-               ++i;
-       }
-       return pseries(relational(var, point), newseq);
+       for (auto & it : newseq)
+               it.coeff += deg;
+       return pseries(relational(var, point), std::move(newseq));
 }
 
 
@@ -1208,15 +1182,13 @@ ex pseries::series(const relational & r, int order, unsigned options) const
                        return *this;
                else {
                        epvector new_seq;
-                       epvector::const_iterator it = seq.begin(), itend = seq.end();
-                       while (it != itend) {
-                               int o = ex_to<numeric>(it->coeff).to_int();
+                       for (auto & it : seq) {
+                               int o = ex_to<numeric>(it.coeff).to_int();
                                if (o >= order) {
                                        new_seq.push_back(expair(Order(_ex1), o));
                                        break;
                                }
-                               new_seq.push_back(*it);
-                               ++it;
+                               new_seq.push_back(it);
                        }
                        return pseries(r, new_seq);
                }
index 32c6d80b6f2a8b0de30c01b62e7bd8284771499a..4dd0691c648ac435b4ef60cbaf1074f6fed28ff5 100644 (file)
@@ -106,9 +106,9 @@ void symbol::read_archive(const archive_node &n, lst &sym_lst)
        n.find_string("name", tmp_name);
 
        // If symbol is in sym_lst, return the existing symbol
-       for (lst::const_iterator it = sym_lst.begin(); it != sym_lst.end(); ++it) {
-               if (is_a<symbol>(*it) && (ex_to<symbol>(*it).name == tmp_name)) {
-                       *this = ex_to<symbol>(*it);
+       for (auto & s : sym_lst) {
+               if (is_a<symbol>(s) && (ex_to<symbol>(s).name == tmp_name)) {
+                       *this = ex_to<symbol>(s);
                        // XXX: This method is responsible for reading realsymbol
                        // and possymbol objects too. But
                        // basic::operator=(const basic& other)
index 71932ffa0362b72bb4275a326cd0030e53a6f2a5..146700397ec83d2b2f6738ea0d29abb909694327 100644 (file)
@@ -123,16 +123,12 @@ void symmetry::archive(archive_node &n) const
        n.add_unsigned("type", type);
 
        if (children.empty()) {
-               std::set<unsigned>::const_iterator i = indices.begin(), iend = indices.end();
-               while (i != iend) {
-                       n.add_unsigned("index", *i);
-                       i++;
+               for (auto & i : indices) {
+                       n.add_unsigned("index", i);
                }
        } else {
-               exvector::const_iterator i = children.begin(), iend = children.end();
-               while (i != iend) {
-                       n.add_ex("child", *i);
-                       i++;
+               for (auto & i : children) {
+                       n.add_ex("child", i);
                }
        }
 }
@@ -161,9 +157,8 @@ int symmetry::compare_same_type(const basic & other) const
                return 1;
        if (this_size < that_size)
                return -1;
-       typedef std::set<unsigned>::const_iterator set_it;
-       set_it end = indices.end();
-       for (set_it i=indices.begin(),j=othersymm.indices.begin(); i!=end; ++i,++j) {
+       auto end = indices.end();
+       for (auto i=indices.begin(),j=othersymm.indices.begin(); i!=end; ++i,++j) {
                if(*i < *j)
                        return 1;
                if(*i > *j)
@@ -194,10 +189,9 @@ unsigned symmetry::calchash() const
                if (!indices.empty())
                        v ^= *(indices.begin());
        } else {
-               for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
-               {
+               for (auto & i : children) {
                        v = rotate_left(v);
-                       v ^= i->gethash();
+                       v ^= i.gethash();
                }
        }
 
@@ -251,7 +245,7 @@ void symmetry::do_print_tree(const print_tree & c, unsigned level) const
 
        c.s << ", indices=(";
        if (!indices.empty()) {
-               std::set<unsigned>::const_iterator i = indices.begin(), end = indices.end();
+               auto i = indices.begin(), end = indices.end();
                --end;
                while (i != end)
                        c.s << *i++ << ",";
@@ -259,10 +253,8 @@ void symmetry::do_print_tree(const print_tree & c, unsigned level) const
        }
        c.s << ")\n";
 
-       exvector::const_iterator i = children.begin(), end = children.end();
-       while (i != end) {
-               i->print(c, level + c.delta_indent);
-               ++i;
+       for (auto & i : children) {
+               i.print(c, level + c.delta_indent);
        }
 }
 
@@ -275,8 +267,8 @@ bool symmetry::has_nonsymmetric() const
        if (type == antisymmetric || type == cyclic)
                return true;
 
-       for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
-               if (ex_to<symmetry>(*i).has_nonsymmetric())
+       for (auto & i : children)
+               if (ex_to<symmetry>(i).has_nonsymmetric())
                        return true;
 
        return false;
@@ -287,8 +279,8 @@ bool symmetry::has_cyclic() const
        if (type == cyclic)
                return true;
 
-       for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
-               if (ex_to<symmetry>(*i).has_cyclic())
+       for (auto & i : children)
+               if (ex_to<symmetry>(i).has_cyclic())
                        return true;
 
        return false;
@@ -408,7 +400,7 @@ public:
                GINAC_ASSERT(is_exactly_a<symmetry>(lh));
                GINAC_ASSERT(is_exactly_a<symmetry>(rh));
                GINAC_ASSERT(ex_to<symmetry>(lh).indices.size() == ex_to<symmetry>(rh).indices.size());
-               std::set<unsigned>::const_iterator ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
+               auto ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
                while (ait != aitend) {
                        int cmpval = v[*ait].compare(v[*bit]);
                        if (cmpval < 0)
@@ -434,7 +426,7 @@ public:
                GINAC_ASSERT(is_exactly_a<symmetry>(lh));
                GINAC_ASSERT(is_exactly_a<symmetry>(rh));
                GINAC_ASSERT(ex_to<symmetry>(lh).indices.size() == ex_to<symmetry>(rh).indices.size());
-               std::set<unsigned>::const_iterator ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
+               auto ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
                while (ait != aitend) {
                        v[*ait].swap(v[*bit]);
                        ++ait; ++bit;
@@ -452,7 +444,7 @@ int canonicalize(exvector::iterator v, const symmetry &symm)
        // Canonicalize children first
        bool something_changed = false;
        int sign = 1;
-       exvector::const_iterator first = symm.children.begin(), last = symm.children.end();
+       auto first = symm.children.begin(), last = symm.children.end();
        while (first != last) {
                GINAC_ASSERT(is_exactly_a<symmetry>(*first));
                int child_sign = canonicalize(v, ex_to<symmetry>(*first));
index 2ef2408d25cd483e5b760f23881e6bc38ca78e92..bb62ed051b9e55530d4173ee5d837ed35d7b9b1b 100644 (file)
@@ -431,8 +431,8 @@ static ex f_find(const exprseq &e)
        exset found;
        e[0].find(e[1], found);
        lst l;
-       for (exset::const_iterator i = found.begin(); i != found.end(); ++i)
-               l.append(*i);
+       for (auto & i : found)
+               l.append(i);
        return l;
 }
 
@@ -486,8 +486,8 @@ static ex f_match(const exprseq &e)
        exmap repls;
        if (e[0].match(e[1], repls)) {
                lst repl_lst;
-               for (exmap::const_iterator i = repls.begin(); i != repls.end(); ++i)
-                       repl_lst.append(relational(i->first, i->second, relational::equal));
+               for (auto & i : repls)
+                       repl_lst.append(relational(i.first, i.second, relational::equal));
                return repl_lst;
        }
        throw std::runtime_error("FAIL");
@@ -736,12 +736,9 @@ static ex f_ginac_function(const exprseq &es, int serial)
 namespace GiNaC {
 static void ginsh_get_ginac_functions(void)
 {
-       vector<function_options> gfv = function::get_registered_functions();
-       vector<function_options>::const_iterator i = gfv.begin(), end = gfv.end();
        unsigned serial = 0;
-       while (i != end) {
-               fcns.insert(make_pair(i->get_name(), fcn_desc(f_ginac_function, i->get_nparams(), serial)));
-               ++i;
+       for (auto & i : function::get_registered_functions()) {
+               fcns.insert(make_pair(i.get_name(), fcn_desc(f_ginac_function, i.get_nparams(), serial)));
                serial++;
        }
 }