From: Richard Kreckel Date: Sat, 7 Nov 2015 12:03:05 +0000 (+0100) Subject: Remove 'discardable' option from ctors of container and derived classes. X-Git-Tag: release_1-7-0~7^2~61 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=85f46b3d72dbafb6fe1fbb9bca32ec612cf8b480 Remove 'discardable' option from ctors of container and derived classes. 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. --- diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 16f83196..56e43bd8 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -105,7 +105,7 @@ clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char r GINAC_ASSERT(is_a(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(other), std::reverse_iterator(self + 1)), true); + *self = ncmul(exvector(std::reverse_iterator(other), std::reverse_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(next_to_last), std::reverse_iterator(self + 1)), true); + ex S = ncmul(exvector(self + 1, next_to_last)); + ex SR = ncmul(exvector(std::reverse_iterator(next_to_last), std::reverse_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(*before_other) && ex_to(*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(save0).get_commutator_sign() * ncmul(v, true); + sum += ex_to(save0).get_commutator_sign() * ncmul(std::move(v)); i->second = canonicalize_clifford(sum); goto next_sym; } diff --git a/ginac/clifford.h b/ginac/clifford.h index bb3a7fec..6af79dbc 100644 --- a/ginac/clifford.h +++ b/ginac/clifford.h @@ -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 diff --git a/ginac/color.cpp b/ginac/color.cpp index 1d006e49..dcc106da 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -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) { } diff --git a/ginac/color.h b/ginac/color.h index e4a11e4a..460e7a9d 100644 --- a/ginac/color.h +++ b/ginac/color.h @@ -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); diff --git a/ginac/container.h b/ginac/container.h index cca5c673..3c1ac47e 100644 --- a/ginac/container.h +++ b/ginac/container.h @@ -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(s)); - else - this->seq = s; + this->seq = s; } explicit container(STLT && v) diff --git a/ginac/function.cppy b/ginac/function.cppy index 0a521e11..fb1d8791 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -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) { } diff --git a/ginac/function.hppy b/ginac/function.hppy index a5605115..b7d7b0d1 100644 --- a/ginac/function.hppy +++ b/ginac/function.hppy @@ -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 diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index 5e63d894..55c9768d 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -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(*it1) || is_exactly_a(*it1)) && (is_exactly_a(*it2) || is_exactly_a(*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; diff --git a/ginac/indexed.h b/ginac/indexed.h index f45f7431..2c4f5511 100644 --- a/ginac/indexed.h +++ b/ginac/indexed.h @@ -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 diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index b37904bb..d15d6ca8 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -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 diff --git a/ginac/ncmul.h b/ginac/ncmul.h index 8e68054a..92bdbe88 100644 --- a/ginac/ncmul.h +++ b/ginac/ncmul.h @@ -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 diff --git a/ginac/power.cpp b/ginac/power.cpp index 491f2d33..b12ff8a4 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -571,7 +571,7 @@ ex power::eval(int level) const if (num_exponent->is_pos_integer() && ebasis.return_type() != return_types::commutative && !is_a(ebasis)) { - return ncmul(exvector(num_exponent->to_int(), ebasis), true); + return ncmul(exvector(num_exponent->to_int(), ebasis)); } }