Remove 'discardable' option from ctors of container and derived classes.
authorRichard Kreckel <kreckel@ginac.de>
Sat, 7 Nov 2015 12:03:05 +0000 (13:03 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sat, 7 Nov 2015 12:03:05 +0000 (13:03 +0100)
The whole idea of this was to allow the ctor to pilfer the data from the
constructed-from object, which is precisely the move semantics which
C++11 supports with rvalue references.

12 files changed:
ginac/clifford.cpp
ginac/clifford.h
ginac/color.cpp
ginac/color.h
ginac/container.h
ginac/function.cppy
ginac/function.hppy
ginac/indexed.cpp
ginac/indexed.h
ginac/ncmul.cpp
ginac/ncmul.h
ginac/power.cpp

index 16f8319..56e43bd 100644 (file)
@@ -105,7 +105,7 @@ clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char r
        GINAC_ASSERT(is_a<idx>(mu));
 }
 
-clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl), metric(metr), commutator_sign(comm_sign)
+clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v) : inherited(not_symmetric(), v), representation_label(rl), metric(metr), commutator_sign(comm_sign)
 {
 }
 
@@ -399,7 +399,7 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                        if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
                                return false;
 
-                       *self = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
+                       *self = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)));
                        std::fill(self + 1, other, _ex1);
                        *other = _ex_2;
                        return true;
@@ -412,8 +412,8 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                                return false;
 
                        exvector::iterator next_to_last = other - 1;
-                       ex S = ncmul(exvector(self + 1, next_to_last), true);
-                       ex SR = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
+                       ex S = ncmul(exvector(self + 1, next_to_last));
+                       ex SR = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)));
 
                        *self = (*next_to_last) * S + SR * (*next_to_last);
                        std::fill(self + 1, other, _ex1);
@@ -428,7 +428,7 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                                return false;
 
                        exvector::iterator next_to_last = other - 1;
-                       ex S = ncmul(exvector(self + 1, next_to_last), true);
+                       ex S = ncmul(exvector(self + 1, next_to_last));
 
                        *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
                        std::fill(self + 1, other + 1, _ex1);
@@ -495,7 +495,7 @@ bool cliffordunit::contract_with(exvector::iterator self, exvector::iterator oth
                                return false;
                        }
                        
-                       ex S = ncmul(exvector(self + 1, before_other), true);
+                       ex S = ncmul(exvector(self + 1, before_other));
 
                        if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
                                *self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other);
@@ -1063,7 +1063,7 @@ ex canonicalize_clifford(const ex & e_)
                                                ex sum = ncmul(v);
                                                it[0] = save1;
                                                it[1] = save0;
-                                               sum += ex_to<clifford>(save0).get_commutator_sign() * ncmul(v, true);
+                                               sum += ex_to<clifford>(save0).get_commutator_sign() * ncmul(std::move(v));
                                                i->second = canonicalize_clifford(sum);
                                                goto next_sym;
                                        }
index bb3a7fe..6af79db 100644 (file)
@@ -46,7 +46,7 @@ public:
        clifford(const ex & b, const ex & mu,  const ex & metr, unsigned char rl = 0, int comm_sign = -1);
 
        // internal constructors
-       clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable = false);
+       clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v);
        clifford(unsigned char rl, const ex & metr, int comm_sign, exvector && v);
 
        // functions overriding virtual functions from base classes
index 1d006e4..dcc106d 100644 (file)
@@ -86,7 +86,7 @@ color::color(const ex & b, const ex & i1, unsigned char rl) : inherited(b, i1),
 {
 }
 
-color::color(unsigned char rl, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl)
+color::color(unsigned char rl, const exvector & v) : inherited(not_symmetric(), v), representation_label(rl)
 {
 }
 
index e4a11e4..460e7a9 100644 (file)
@@ -46,7 +46,7 @@ public:
        color(const ex & b, const ex & i1, unsigned char rl = 0);
 
        // internal constructors
-       color(unsigned char rl, const exvector & v, bool discardable = false);
+       color(unsigned char rl, const exvector & v);
        color(unsigned char rl, exvector && v);
        void archive(archive_node& n) const;
        void read_archive(const archive_node& n, lst& sym_lst);
index cca5c67..3c1ac47 100644 (file)
@@ -142,14 +142,10 @@ protected:
 
        // constructors
 public:
-       container(STLT const & s, bool discardable = false)
+       container(STLT const & s)
        {
                setflag(get_default_flags());
-
-               if (discardable)
-                       this->seq.swap(const_cast<STLT &>(s));
-               else
-                       this->seq = s;
+               this->seq = s;
        }
 
        explicit container(STLT && v)
index 0a521e1..fb1d879 100644 (file)
@@ -242,8 +242,8 @@ function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
        clearflag(status_flags::evaluated);
 }
 
-function::function(unsigned ser, const exvector & v, bool discardable) 
-  : exprseq(v,discardable), serial(ser)
+function::function(unsigned ser, const exvector & v)
+  : exprseq(v), serial(ser)
 {
 }
 
index a560511..b7d7b0d 100644 (file)
@@ -222,7 +222,7 @@ public:
 ---
        // end of generated lines
        function(unsigned ser, const exprseq & es);
-       function(unsigned ser, const exvector & v, bool discardable = false);
+       function(unsigned ser, const exvector & v);
        function(unsigned ser, exvector && v);
        
        // functions overriding virtual functions from base classes
index 5e63d89..55c9768 100644 (file)
@@ -117,7 +117,7 @@ indexed::indexed(const symmetry & symm, const exprseq & es) : inherited(es), sym
 {
 }
 
-indexed::indexed(const symmetry & symm, const exvector & v, bool discardable) : inherited(v, discardable), symtree(symm)
+indexed::indexed(const symmetry & symm, const exvector & v) : inherited(v), symtree(symm)
 {
 }
 
@@ -874,7 +874,7 @@ contraction_done:
                                        // the product
                                        bool is_a_product = (is_exactly_a<mul>(*it1) || is_exactly_a<ncmul>(*it1)) &&
                                                            (is_exactly_a<mul>(*it2) || is_exactly_a<ncmul>(*it2));
-                                       ex r = (non_commutative ? ex(ncmul(v, true)) : ex(mul(v)));
+                                       ex r = (non_commutative ? ex(ncmul(std::move(v))) : ex(mul(std::move(v))));
 
                                        // If new expression is a product we can call this function again,
                                        // otherwise we need to pass argument to simplify_indexed() to be expanded
@@ -941,7 +941,7 @@ contraction_done:
 
        ex r;
        if (something_changed)
-               r = non_commutative ? ex(ncmul(v, true)) : ex(mul(v));
+               r = non_commutative ? ex(ncmul(std::move(v))) : ex(mul(std::move(v)));
        else
                r = e;
 
index f45f743..2c4f551 100644 (file)
@@ -138,7 +138,7 @@ public:
 
        // internal constructors
        indexed(const symmetry & symm, const exprseq & es);
-       indexed(const symmetry & symm, const exvector & v, bool discardable = false);
+       indexed(const symmetry & symm, const exvector & v);
        indexed(const symmetry & symm, exvector && v);
 
        // functions overriding virtual functions from base classes
index b37904b..d15d6ca 100644 (file)
@@ -80,7 +80,7 @@ ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3,
 {
 }
 
-ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable)
+ncmul::ncmul(const exvector & v) : inherited(v)
 {
 }
 
@@ -179,7 +179,7 @@ ex ncmul::expand(unsigned options) const
                        term[positions_of_adds[i]] = rename_dummy_indices_uniquely(va, expanded_seq[positions_of_adds[i]].op(k[i]), true);
                }
 
-               distrseq.push_back((new ncmul(term, true))->
+               distrseq.push_back((new ncmul(std::move(term)))->
                                    setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0)));
 
                // increment k[]
@@ -233,7 +233,7 @@ ex ncmul::coeff(const ex & s, int n) const
                // if a non-zero power of s is found, the resulting product will be 0
                for (auto & it : seq)
                        coeffseq.push_back(it.coeff(s,n));
-               return (new ncmul(std::move(coeffseq),1))->setflag(status_flags::dynallocated);
+               return (new ncmul(std::move(coeffseq)))->setflag(status_flags::dynallocated);
        }
                 
        bool coeff_found = false;
@@ -248,7 +248,7 @@ ex ncmul::coeff(const ex & s, int n) const
        }
 
        if (coeff_found)
-               return (new ncmul(std::move(coeffseq), 1))->setflag(status_flags::dynallocated);
+               return (new ncmul(std::move(coeffseq)))->setflag(status_flags::dynallocated);
        
        return _ex0;
 }
@@ -364,8 +364,8 @@ ex ncmul::eval(int level) const
                        else
                                noncommutativeseq.push_back(assocseq[i]);
                }
-               commutativeseq.push_back((new ncmul(noncommutativeseq,1))->setflag(status_flags::dynallocated));
-               return (new mul(commutativeseq))->setflag(status_flags::dynallocated);
+               commutativeseq.push_back((new ncmul(std::move(noncommutativeseq)))->setflag(status_flags::dynallocated));
+               return (new mul(std::move(commutativeseq)))->setflag(status_flags::dynallocated);
        }
                
        // ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2))
@@ -480,7 +480,7 @@ ex ncmul::conjugate() const
                --i;
                ev.push_back(i->conjugate());
        }
-       return (new ncmul(std::move(ev), true))->setflag(status_flags::dynallocated).eval();
+       return (new ncmul(std::move(ev)))->setflag(status_flags::dynallocated).eval();
 }
 
 ex ncmul::real_part() const
index 8e68054..92bdbe8 100644 (file)
@@ -49,7 +49,7 @@ public:
              const ex & f4, const ex & f5);
        ncmul(const ex & f1, const ex & f2, const ex & f3,
              const ex & f4, const ex & f5, const ex & f6);
-       ncmul(const exvector & v, bool discardable=false);
+       ncmul(const exvector & v);
        ncmul(exvector && v);
 
        // functions overriding virtual functions from base classes
index 491f2d3..b12ff8a 100644 (file)
@@ -571,7 +571,7 @@ ex power::eval(int level) const
                if (num_exponent->is_pos_integer() &&
                    ebasis.return_type() != return_types::commutative &&
                    !is_a<matrix>(ebasis)) {
-                       return ncmul(exvector(num_exponent->to_int(), ebasis), true);
+                       return ncmul(exvector(num_exponent->to_int(), ebasis));
                }
        }