GINAC_ASSERT(is_canonical());
}
-add::add(std::auto_ptr<epvector> vp, const ex & oc)
+add::add(epvector && vp, const ex & oc)
{
- GINAC_ASSERT(vp.get()!=0);
overall_coeff = oc;
- construct_from_epvector(*vp);
+ construct_from_epvector(std::move(vp));
GINAC_ASSERT(is_canonical());
}
ex add::coeff(const ex & s, int n) const
{
- std::auto_ptr<epvector> coeffseq(new epvector);
- std::auto_ptr<epvector> coeffseq_cliff(new epvector);
+ epvector coeffseq;
+ epvector coeffseq_cliff;
int rl = clifford_max_label(s);
bool do_clifford = (rl != -1);
bool nonscalar = false;
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 ? coeffseq_cliff : coeffseq,
+ return (new add(nonscalar ? std::move(coeffseq_cliff) : std::move(coeffseq),
n==0 ? overall_coeff : _ex0))->setflag(status_flags::dynallocated);
}
* @param level cut-off in recursive evaluation */
ex add::eval(int level) const
{
- std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
- if (evaled_seqp.get()) {
+ epvector evaled = evalchildren(level);
+ if (!evaled.empty()) {
// do more evaluation later
- return (new add(evaled_seqp, overall_coeff))->
- setflag(status_flags::dynallocated);
+ return (new add(std::move(evaled), overall_coeff))->
+ setflag(status_flags::dynallocated);
}
-
+
#ifdef DO_GINAC_ASSERT
epvector::const_iterator i = seq.begin(), end = seq.end();
while (i != end) {
++j;
}
if (terms_to_collect) {
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq_size - 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));
else
- s->push_back(*j);
+ s.push_back(*j);
++j;
}
- return (new add(s, ex_to<numeric>(overall_coeff).add_dyn(oc)))
+ return (new add(std::move(s), ex_to<numeric>(overall_coeff).add_dyn(oc)))
->setflag(status_flags::dynallocated);
}
{
// Evaluate children first and add up all matrices. Stop if there's one
// term that is not a matrix.
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
bool all_matrices = true;
bool first_term = true;
epvector::const_iterator it = seq.begin(), itend = seq.end();
while (it != itend) {
const ex &m = recombine_pair_to_ex(*it).evalm();
- s->push_back(split_ex_to_pair(m));
+ s.push_back(split_ex_to_pair(m));
if (is_a<matrix>(m)) {
if (first_term) {
sum = ex_to<matrix>(m);
if (all_matrices)
return sum + overall_coeff;
else
- return (new add(s, overall_coeff))->setflag(status_flags::dynallocated);
+ return (new add(std::move(s), overall_coeff))->setflag(status_flags::dynallocated);
}
ex add::conjugate() const
* @see ex::diff */
ex add::derivative(const symbol & y) const
{
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
// 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));
+ s.push_back(combine_ex_with_coeff_to_pair(i->rest.diff(y), i->coeff));
++i;
}
- return (new add(s, _ex0))->setflag(status_flags::dynallocated);
+ return (new add(std::move(s), _ex0))->setflag(status_flags::dynallocated);
}
int add::compare_same_type(const basic & other) const
}
// Note: do_index_renaming is ignored because it makes no sense for an add.
-ex add::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming) const
+ex add::thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming) const
{
- return (new add(vp,oc))->setflag(status_flags::dynallocated);
+ return (new add(std::move(vp), oc))->setflag(status_flags::dynallocated);
}
expair add::split_ex_to_pair(const ex & e) const
ex add::expand(unsigned options) const
{
- std::auto_ptr<epvector> vp = expandchildren(options);
- if (vp.get() == 0) {
- // the terms have not changed, so it is safe to declare this expanded
+ epvector expanded = expandchildren(options);
+ if (expanded.empty())
return (options == 0) ? setflag(status_flags::expanded) : *this;
- }
- return (new add(vp, overall_coeff))->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
+ return (new add(std::move(expanded), overall_coeff))->setflag(status_flags::dynallocated |
+ (options == 0 ? status_flags::expanded : 0));
}
} // namespace GiNaC
add(const exvector & v);
add(const epvector & v);
add(const epvector & v, const ex & oc);
- add(std::auto_ptr<epvector> vp, const ex & oc);
+ add(epvector && vp, const ex & oc);
// functions overriding virtual functions from base classes
public:
unsigned return_type() const;
return_type_t return_type_tinfo() const;
ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
- ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
+ ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) const;
expair split_ex_to_pair(const ex & e) const;
expair combine_ex_with_coeff_to_pair(const ex & e,
const ex & c) const;
{
}
-clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr), commutator_sign(comm_sign)
+clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, exvector && v) : inherited(not_symmetric(), std::move(v)), representation_label(rl), metric(metr), commutator_sign(comm_sign)
{
}
return clifford(representation_label, metric, commutator_sign, v);
}
-ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
+ex clifford::thiscontainer(exvector && v) const
{
- return clifford(representation_label, metric, commutator_sign, vp);
+ return clifford(representation_label, metric, commutator_sign, std::move(v));
}
ex diracgamma5::conjugate() const
// 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, std::auto_ptr<exvector> vp);
+ clifford(unsigned char rl, const ex & metr, int comm_sign, exvector && v);
// functions overriding virtual functions from base classes
public:
ex eval_ncmul(const exvector & v) const;
bool match_same_type(const basic & other) const;
ex thiscontainer(const exvector & v) const;
- ex thiscontainer(std::auto_ptr<exvector> vp) const;
+ ex thiscontainer(exvector && v) const;
unsigned return_type() const { return return_types::noncommutative; }
return_type_t return_type_tinfo() const;
// non-virtual functions in this class
{
}
-color::color(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl)
+color::color(unsigned char rl, exvector && v) : inherited(not_symmetric(), std::move(v)), representation_label(rl)
{
}
return color(representation_label, v);
}
-ex color::thiscontainer(std::auto_ptr<exvector> vp) const
+ex color::thiscontainer(exvector && v) const
{
- return color(representation_label, vp);
+ return color(representation_label, std::move(v));
}
/** Given a vector iv3 of three indices and a vector iv2 of two indices that
// internal constructors
color(unsigned char rl, const exvector & v, bool discardable = false);
- color(unsigned char rl, std::auto_ptr<exvector> vp);
+ color(unsigned char rl, exvector && v);
void archive(archive_node& n) const;
void read_archive(const archive_node& n, lst& sym_lst);
ex eval_ncmul(const exvector & v) const;
bool match_same_type(const basic & other) const;
ex thiscontainer(const exvector & v) const;
- ex thiscontainer(std::auto_ptr<exvector> vp) const;
+ ex thiscontainer(exvector && v) const;
unsigned return_type() const { return return_types::noncommutative; }
return_type_t return_type_tinfo() const;
this->seq = s;
}
- explicit container(std::auto_ptr<STLT> vp)
+ explicit container(STLT && v)
{
setflag(get_default_flags());
- this->seq.swap(*vp);
+ this->seq.swap(v);
}
container(exvector::const_iterator b, exvector::const_iterator e)
virtual ex thiscontainer(const STLT & v) const { return container(v); }
/** Similar to duplicate(), but with a preset sequence (which gets
- * deleted). Must be overridden by derived classes. */
- virtual ex thiscontainer(std::auto_ptr<STLT> vp) const { return container(vp); }
+ * pilfered). Must be overridden by derived classes. */
+ virtual ex thiscontainer(STLT && v) const { return container(std::move(v)); }
virtual void printseq(const print_context & c, char openbracket, char delim,
char closebracket, unsigned this_precedence,
void do_print_python(const print_python & c, unsigned level) const;
void do_print_python_repr(const print_python_repr & c, unsigned level) const;
STLT evalchildren(int level) const;
- std::auto_ptr<STLT> subschildren(const exmap & m, unsigned options = 0) const;
+ STLT subschildren(const exmap & m, unsigned options = 0) const;
};
/** Default constructor */
// f(x).subs(x==f^-1(x))
// -> f(f^-1(x)) [subschildren]
// -> x [eval] /* must not subs(x==f^-1(x))! */
- std::auto_ptr<STLT> vp = subschildren(m, options);
- if (vp.get()) {
- ex result(thiscontainer(vp));
+ STLT subsed = subschildren(m, options);
+ if (!subsed.empty()) {
+ ex result(thiscontainer(subsed));
if (is_a<container<C> >(result))
return ex_to<basic>(result).subs_one_level(m, options);
else
}
template <template <class T, class = std::allocator<T> > class C>
-std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exmap & m, unsigned options) const
+typename container<C>::STLT container<C>::subschildren(const exmap & m, unsigned options) const
{
- // returns a NULL pointer if nothing had to be substituted
- // returns a pointer to a newly created STLT otherwise
- // (and relinquishes responsibility for the STLT)
+ // returns an empty container if nothing had to be substituted
+ // returns a STLT with substituted elements otherwise
const_iterator cit = this->seq.begin(), end = this->seq.end();
while (cit != end) {
if (!are_ex_trivially_equal(*cit, subsed_ex)) {
// copy first part of seq which hasn't changed
- std::auto_ptr<STLT> s(new STLT(this->seq.begin(), cit));
- this->reserve(*s, this->seq.size());
+ STLT s(this->seq.begin(), cit);
+ this->reserve(s, this->seq.size());
// insert changed element
- s->push_back(subsed_ex);
+ s.push_back(subsed_ex);
++cit;
// copy rest
while (cit != end) {
- s->push_back(cit->subs(m, options));
+ s.push_back(cit->subs(m, options));
++cit;
}
++cit;
}
- return std::auto_ptr<STLT>(0); // nothing has changed
+ return STLT(); // nothing has changed
}
} // namespace GiNaC
// This should return an ex*, but that would be a pointer to a
// temporary value
- std::auto_ptr<ex> operator->() const
+ std::unique_ptr<ex> operator->() const
{
- return std::auto_ptr<ex>(new ex(operator*()));
+ return std::unique_ptr<ex>(new ex(operator*()));
}
ex operator[](difference_type n) const
GINAC_ASSERT(is_canonical());
}
-expairseq::expairseq(std::auto_ptr<epvector> vp, const ex &oc, bool do_index_renaming)
+expairseq::expairseq(epvector && vp, const ex &oc, bool do_index_renaming)
: overall_coeff(oc)
{
- GINAC_ASSERT(vp.get()!=0);
GINAC_ASSERT(is_a<numeric>(oc));
- construct_from_epvector(*vp, do_index_renaming);
+ construct_from_epvector(std::move(vp), do_index_renaming);
GINAC_ASSERT(is_canonical());
}
ex expairseq::map(map_function &f) const
{
- std::auto_ptr<epvector> v(new epvector);
- v->reserve(seq.size()+1);
+ 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))));
+ v.push_back(split_ex_to_pair(f(recombine_pair_to_ex(*cit))));
++cit;
}
if (overall_coeff.is_equal(default_overall_coeff()))
- return thisexpairseq(v, default_overall_coeff(), true);
+ return thisexpairseq(std::move(v), default_overall_coeff(), true);
else {
ex newcoeff = f(overall_coeff);
if(is_a<numeric>(newcoeff))
- return thisexpairseq(v, newcoeff, true);
+ return thisexpairseq(std::move(v), newcoeff, true);
else {
- v->push_back(split_ex_to_pair(newcoeff));
- return thisexpairseq(v, default_overall_coeff(), true);
+ v.push_back(split_ex_to_pair(newcoeff));
+ return thisexpairseq(std::move(v), default_overall_coeff(), true);
}
}
}
{
if ((level==1) && (flags &status_flags::evaluated))
return *this;
-
- std::auto_ptr<epvector> vp = evalchildren(level);
- if (vp.get() == 0)
+
+ epvector evaled = evalchildren(level);
+ if (!evaled.empty())
+ return (new expairseq(std::move(evaled), overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
+ else
return this->hold();
-
- return (new expairseq(vp, overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
}
epvector* conjugateepvector(const epvector&epv)
{
epvector* newepv = conjugateepvector(seq);
ex x = overall_coeff.conjugate();
- if (!newepv && are_ex_trivially_equal(x, overall_coeff)) {
+ if (newepv) {
+ ex result = thisexpairseq(std::move(*newepv), x);
+ delete newepv;
+ return result;
+ }
+ if (are_ex_trivially_equal(x, overall_coeff)) {
return *this;
}
- ex result = thisexpairseq(newepv ? *newepv : seq, x);
- delete newepv;
- return result;
+ return thisexpairseq(seq, x);
}
bool expairseq::match(const ex & pattern, exmap & repl_lst) const
// it has already been matched before, in which case the matches
// must be equal)
size_t num = ops.size();
- std::auto_ptr<epvector> vp(new epvector);
- vp->reserve(num);
+ epvector vp;
+ vp.reserve(num);
for (size_t i=0; i<num; i++)
- vp->push_back(split_ex_to_pair(ops[i]));
- ex rest = thisexpairseq(vp, default_overall_coeff());
+ 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)) {
ex expairseq::subs(const exmap & m, unsigned options) const
{
- std::auto_ptr<epvector> vp = subschildren(m, options);
- if (vp.get())
- return ex_to<basic>(thisexpairseq(vp, overall_coeff, (options & subs_options::no_index_renaming) == 0));
+ epvector subsed = subschildren(m, options);
+ if (!subsed.empty())
+ return ex_to<basic>(thisexpairseq(std::move(subsed), overall_coeff, (options & subs_options::no_index_renaming) == 0));
else if ((options & subs_options::algebraic) && is_exactly_a<mul>(*this))
return static_cast<const mul *>(this)->algebraic_subs_mul(m, options);
else
const epvector::const_iterator end = seq.end();
while (i != end) {
v ^= i->rest.gethash();
- // rotation spoils commutativity!
v = rotate_left(v);
v ^= i->coeff.gethash();
++i;
ex expairseq::expand(unsigned options) const
{
- std::auto_ptr<epvector> vp = expandchildren(options);
- if (vp.get())
- return thisexpairseq(vp, overall_coeff);
- else {
- // The terms have not changed, so it is safe to declare this expanded
- return (options == 0) ? setflag(status_flags::expanded) : *this;
+ epvector expanded = expandchildren(options);
+ if (!expanded.empty()) {
+ return thisexpairseq(std::move(expanded), overall_coeff);
}
+ return (options == 0) ? setflag(status_flags::expanded) : *this;
}
//////////
return expairseq(v, oc, do_index_renaming);
}
-ex expairseq::thisexpairseq(std::auto_ptr<epvector> vp, const ex &oc, bool do_index_renaming) const
+ex expairseq::thisexpairseq(epvector && vp, const ex &oc, bool do_index_renaming) const
{
- return expairseq(vp, oc, do_index_renaming);
+ return expairseq(std::move(vp), oc, do_index_renaming);
}
void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const
if (needs_further_processing) {
epvector v = seq;
seq.clear();
- construct_from_epvector(v);
+ construct_from_epvector(std::move(v));
}
}
if (needs_further_processing) {
epvector v = seq;
seq.clear();
- construct_from_epvector(v);
+ construct_from_epvector(std::move(v));
}
}
combine_same_terms_sorted_seq();
}
+void expairseq::construct_from_epvector(epvector &&v, bool do_index_renaming)
+{
+ // simplifications: +(a,+(b,c),d) -> +(a,b,c,d) (associativity)
+ // +(d,b,c,a) -> +(a,b,c,d) (canonicalization)
+ // +(...,x,*(x,c1),*(x,c2)) -> +(...,*(x,1+c1+c2)) (c1, c2 numeric)
+ // same for (+,*) -> (*,^)
+
+ make_flat(std::move(v), do_index_renaming);
+ canonicalize();
+ combine_same_terms_sorted_seq();
+}
+
/** Combine this expairseq with argument exvector.
* It cares for associativity as well as for special handling of numerics. */
void expairseq::make_flat(const exvector &v)
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));
+ 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))));
- //seq.push_back(combine_pair_with_coeff_to_pair(*cit_s,
- // (*cit).coeff));
++cit_s;
}
} else {
if (needs_further_processing) {
epvector v = seq;
seq.clear();
- construct_from_epvector(v);
+ construct_from_epvector(std::move(v));
}
}
return 1;
}
-
/** Member-wise expand the expairs in this sequence.
*
* @see expairseq::expand()
- * @return pointer to epvector containing expanded pairs or zero pointer,
- * if no members were changed. */
-std::auto_ptr<epvector> expairseq::expandchildren(unsigned options) const
+ * @return epvector containing expanded pairs, empty if no members
+ * had to be changed. */
+epvector expairseq::expandchildren(unsigned options) const
{
const epvector::const_iterator last = seq.end();
epvector::const_iterator cit = seq.begin();
if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
// something changed, copy seq, eval and return it
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
// copy parts of seq which are known not to have changed
epvector::const_iterator cit2 = seq.begin();
while (cit2!=cit) {
- s->push_back(*cit2);
+ s.push_back(*cit2);
++cit2;
}
// copy first changed element
- s->push_back(combine_ex_with_coeff_to_pair(expanded_ex,
- cit2->coeff));
+ s.push_back(combine_ex_with_coeff_to_pair(expanded_ex,
+ cit2->coeff));
++cit2;
// copy rest
while (cit2!=last) {
- s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.expand(options),
- cit2->coeff));
+ s.push_back(combine_ex_with_coeff_to_pair(cit2->rest.expand(options),
+ cit2->coeff));
++cit2;
}
return s;
++cit;
}
- return std::auto_ptr<epvector>(0); // signalling nothing has changed
+ return epvector(); // empty signalling nothing has changed
}
/** Member-wise evaluate the expairs in this sequence.
*
* @see expairseq::eval()
- * @return pointer to epvector containing evaluated pairs or zero pointer,
- * if no members were changed. */
-std::auto_ptr<epvector> expairseq::evalchildren(int level) const
+ * @return epvector containing evaluated pairs, empty if no members
+ * had to be changed. */
+epvector expairseq::evalchildren(int level) const
{
- // returns a NULL pointer if nothing had to be evaluated
- // returns a pointer to a newly created epvector otherwise
- // (which has to be deleted somewhere else)
-
if (level==1)
- return std::auto_ptr<epvector>(0);
+ return epvector(); // nothing had to be evaluated
if (level == -max_recursion_level)
throw(std::runtime_error("max recursion level reached"));
epvector::const_iterator last = seq.end();
epvector::const_iterator cit = seq.begin();
while (cit!=last) {
- const ex &evaled_ex = cit->rest.eval(level);
+ const ex evaled_ex = cit->rest.eval(level);
if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
// something changed, copy seq, eval and return it
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
// copy parts of seq which are known not to have changed
epvector::const_iterator cit2=seq.begin();
while (cit2!=cit) {
- s->push_back(*cit2);
+ s.push_back(*cit2);
++cit2;
}
// copy first changed element
- s->push_back(combine_ex_with_coeff_to_pair(evaled_ex,
- cit2->coeff));
+ s.push_back(combine_ex_with_coeff_to_pair(evaled_ex,
+ cit2->coeff));
++cit2;
// copy rest
while (cit2!=last) {
- s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.eval(level),
- cit2->coeff));
+ s.push_back(combine_ex_with_coeff_to_pair(cit2->rest.eval(level),
+ cit2->coeff));
++cit2;
}
- return s;
+ return std::move(s);
}
++cit;
}
-
- return std::auto_ptr<epvector>(0); // signalling nothing has changed
+
+ return epvector(); // signalling nothing has changed
}
/** Member-wise substitute in this sequence.
*
* @see expairseq::subs()
- * @return pointer to epvector containing pairs after application of subs,
- * or NULL pointer if no members were changed. */
-std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned options) const
+ * @return epvector containing expanded pairs, empty if no members
+ * had to be changed. */
+epvector expairseq::subschildren(const exmap & m, unsigned options) const
{
// When any of the objects to be substituted is a product or power
// we have to recombine the pairs because the numeric coefficients may
if (!are_ex_trivially_equal(orig_ex, subsed_ex)) {
// Something changed, copy seq, subs and return it
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
// Copy parts of seq which are known not to have changed
- s->insert(s->begin(), seq.begin(), cit);
+ s.insert(s.begin(), seq.begin(), cit);
// Copy first changed element
- s->push_back(split_ex_to_pair(subsed_ex));
+ s.push_back(split_ex_to_pair(subsed_ex));
++cit;
// Copy rest
while (cit != last) {
- s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(m, options)));
+ s.push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(m, options)));
++cit;
}
return s;
if (!are_ex_trivially_equal(cit->rest, subsed_ex)) {
// Something changed, copy seq, subs and return it
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
// Copy parts of seq which are known not to have changed
- s->insert(s->begin(), seq.begin(), cit);
+ s.insert(s.begin(), seq.begin(), cit);
// Copy first changed element
- s->push_back(combine_ex_with_coeff_to_pair(subsed_ex, cit->coeff));
+ s.push_back(combine_ex_with_coeff_to_pair(subsed_ex, cit->coeff));
++cit;
// Copy rest
while (cit != last) {
- s->push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(m, options), cit->coeff));
+ s.push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(m, options), cit->coeff));
++cit;
}
return s;
}
// Nothing has changed
- return std::auto_ptr<epvector>(0);
+ return epvector();
}
//////////
expairseq(const ex & lh, const ex & rh);
expairseq(const exvector & v);
expairseq(const epvector & v, const ex & oc, bool do_index_renaming = false);
- expairseq(std::auto_ptr<epvector>, const ex & oc, bool do_index_renaming = false);
+ expairseq(epvector && vp, const ex & oc, bool do_index_renaming = false);
// functions overriding virtual functions from base classes
public:
// new virtual functions which can be overridden by derived classes
protected:
virtual ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
- virtual ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
+ virtual ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) const;
virtual void printseq(const print_context & c, char delim,
unsigned this_precedence,
unsigned upper_precedence) const;
const ex & e);
void construct_from_exvector(const exvector & v);
void construct_from_epvector(const epvector & v, bool do_index_renaming = false);
+ void construct_from_epvector(epvector && v, bool do_index_renaming = false);
void make_flat(const exvector & v);
void make_flat(const epvector & v, bool do_index_renaming = false);
void canonicalize();
void combine_same_terms_sorted_seq();
bool is_canonical() const;
- std::auto_ptr<epvector> expandchildren(unsigned options) const;
- std::auto_ptr<epvector> evalchildren(int level) const;
- std::auto_ptr<epvector> subschildren(const exmap & m, unsigned options = 0) const;
+ epvector expandchildren(unsigned options) const;
+ epvector evalchildren(int level) const;
+ epvector subschildren(const exmap & m, unsigned options = 0) const;
// member variables
{
}
-fderivative::fderivative(unsigned ser, const paramset & params, std::auto_ptr<exvector> vp) : function(ser, vp), parameter_set(params)
+fderivative::fderivative(unsigned ser, const paramset & params, exvector && v) : function(ser, std::move(v)), parameter_set(params)
{
}
return fderivative(serial, parameter_set, v);
}
-ex fderivative::thiscontainer(std::auto_ptr<exvector> vp) const
+ex fderivative::thiscontainer(exvector && v) const
{
- return fderivative(serial, parameter_set, vp);
+ return fderivative(serial, parameter_set, std::move(v));
}
/** Implementation of ex::diff() for derivatives. It applies the chain rule.
fderivative(unsigned ser, const paramset & params, const exvector & args);
// internal constructors
- fderivative(unsigned ser, const paramset & params, std::auto_ptr<exvector> vp);
+ fderivative(unsigned ser, const paramset & params, exvector && v);
// functions overriding virtual functions from base classes
public:
ex evalf(int level = 0) const;
ex series(const relational & r, int order, unsigned options = 0) const;
ex thiscontainer(const exvector & v) const;
- ex thiscontainer(std::auto_ptr<exvector> vp) const;
+ ex thiscontainer(exvector && v) const;
void archive(archive_node& n) const;
void read_archive(const archive_node& n, lst& syms);
protected:
{
}
-function::function(unsigned ser, std::auto_ptr<exvector> vp)
- : exprseq(vp), serial(ser)
+function::function(unsigned ser, exvector && v)
+ : exprseq(std::move(v)), serial(ser)
{
}
return function(serial, v);
}
-ex function::thiscontainer(std::auto_ptr<exvector> vp) const
+ex function::thiscontainer(exvector && v) const
{
- return function(serial, vp);
+ return function(serial, std::move(v));
}
/** Implementation of ex::series for functions.
// end of generated lines
function(unsigned ser, const exprseq & es);
function(unsigned ser, const exvector & v, bool discardable = false);
- function(unsigned ser, std::auto_ptr<exvector> vp);
+ function(unsigned ser, exvector && v);
// functions overriding virtual functions from base classes
public:
unsigned calchash() const;
ex series(const relational & r, int order, unsigned options = 0) const;
ex thiscontainer(const exvector & v) const;
- ex thiscontainer(std::auto_ptr<exvector> vp) const;
+ ex thiscontainer(exvector && v) const;
ex conjugate() const;
ex real_part() const;
ex imag_part() const;
{
}
-indexed::indexed(const symmetry & symm, std::auto_ptr<exvector> vp) : inherited(vp), symtree(symm)
+indexed::indexed(const symmetry & symm, exvector && v) : inherited(std::move(v)), symtree(symm)
{
}
return indexed(ex_to<symmetry>(symtree), v);
}
-ex indexed::thiscontainer(std::auto_ptr<exvector> vp) const
+ex indexed::thiscontainer(exvector && v) const
{
- return indexed(ex_to<symmetry>(symtree), vp);
+ return indexed(ex_to<symmetry>(symtree), std::move(v));
}
unsigned indexed::return_type() const
// internal constructors
indexed(const symmetry & symm, const exprseq & es);
indexed(const symmetry & symm, const exvector & v, bool discardable = false);
- indexed(const symmetry & symm, std::auto_ptr<exvector> vp);
+ indexed(const symmetry & symm, exvector && v);
// functions overriding virtual functions from base classes
public:
protected:
ex derivative(const symbol & s) const;
ex thiscontainer(const exvector & v) const;
- ex thiscontainer(std::auto_ptr<exvector> vp) const;
+ ex thiscontainer(exvector && v) const;
unsigned return_type() const;
return_type_t return_type_tinfo() const { return op(0).return_type_tinfo(); }
ex expand(unsigned options = 0) const;
GINAC_ASSERT(is_canonical());
}
-mul::mul(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming)
+mul::mul(epvector && vp, const ex & oc, bool do_index_renaming)
{
- GINAC_ASSERT(vp.get()!=0);
overall_coeff = oc;
- construct_from_epvector(*vp, do_index_renaming);
+ construct_from_epvector(std::move(vp), do_index_renaming);
GINAC_ASSERT(is_canonical());
}
* @param level cut-off in recursive evaluation */
ex mul::eval(int level) const
{
- std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
- if (evaled_seqp.get()) {
+ epvector evaled = evalchildren(level);
+ if (!evaled.empty()) {
// do more evaluation later
- return (new mul(evaled_seqp, overall_coeff))->
- setflag(status_flags::dynallocated);
+ return (new mul(std::move(evaled), overall_coeff))->
+ setflag(status_flags::dynallocated);
}
-
+
if (flags & status_flags::evaluated) {
GINAC_ASSERT(seq.size()>0);
GINAC_ASSERT(seq.size()>1 || !overall_coeff.is_equal(_ex1));
ex_to<numeric>((*seq.begin()).coeff).is_equal(*_num1_p)) {
// *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
const add & addref = ex_to<add>((*seq.begin()).rest);
- std::auto_ptr<epvector> distrseq(new epvector);
- distrseq->reserve(addref.seq.size());
+ 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));
+ distrseq.push_back(addref.combine_pair_with_coeff_to_pair(*i, overall_coeff));
++i;
}
- return (new add(distrseq,
+ return (new add(std::move(distrseq),
ex_to<numeric>(addref.overall_coeff).
mul_dyn(ex_to<numeric>(overall_coeff)))
)->setflag(status_flags::dynallocated | status_flags::evaluated);
epvector::const_iterator last = seq.end();
epvector::const_iterator i = seq.begin();
epvector::const_iterator j = seq.begin();
- std::auto_ptr<epvector> s(new epvector);
+ epvector s;
numeric oc = *_num1_p;
bool something_changed = false;
while (i!=last) {
}
if (! something_changed) {
- s->reserve(seq_size);
+ s.reserve(seq_size);
something_changed = true;
}
while ((j!=i) && (j!=last)) {
- s->push_back(*j);
+ s.push_back(*j);
++j;
}
for (epvector::iterator ai = primitive->seq.begin(); ai != primitive->seq.end(); ++ai)
ai->coeff = ex_to<numeric>(ai->coeff).div_dyn(c);
- s->push_back(expair(*primitive, _ex1));
+ s.push_back(expair(*primitive, _ex1));
++i;
++j;
}
if (something_changed) {
while (j!=last) {
- s->push_back(*j);
+ s.push_back(*j);
++j;
}
- return (new mul(s, ex_to<numeric>(overall_coeff).mul_dyn(oc))
+ return (new mul(std::move(s), ex_to<numeric>(overall_coeff).mul_dyn(oc))
)->setflag(status_flags::dynallocated);
}
}
if (level==-max_recursion_level)
throw(std::runtime_error("max recursion level reached"));
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ 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));
+ s.push_back(combine_ex_with_coeff_to_pair(i->rest.evalf(level),
+ i->coeff));
++i;
}
- return mul(s, overall_coeff.evalf(level));
+ return mul(std::move(s), overall_coeff.evalf(level));
}
void mul::find_real_imag(ex & rp, ex & ip) const
// Evaluate children first, look whether there are any matrices at all
// (there can be either no matrices or one matrix; if there were more
// than one matrix, it would be a non-commutative product)
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
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();
- s->push_back(split_ex_to_pair(m));
+ s.push_back(split_ex_to_pair(m));
if (is_a<matrix>(m)) {
have_matrix = true;
- the_matrix = s->end() - 1;
+ the_matrix = s.end() - 1;
}
++i;
}
// The product contained a matrix. We will multiply all other factors
// into that matrix.
matrix m = ex_to<matrix>(the_matrix->rest);
- s->erase(the_matrix);
- ex scalar = (new mul(s, overall_coeff))->setflag(status_flags::dynallocated);
+ s.erase(the_matrix);
+ ex scalar = (new mul(std::move(s), overall_coeff))->setflag(status_flags::dynallocated);
return m.mul_scalar(scalar);
} else
- return (new mul(s, overall_coeff))->setflag(status_flags::dynallocated);
+ return (new mul(std::move(s), overall_coeff))->setflag(status_flags::dynallocated);
}
ex mul::eval_ncmul(const exvector & v) const
return (new mul(v, oc, do_index_renaming))->setflag(status_flags::dynallocated);
}
-ex mul::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming) const
+ex mul::thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming) const
{
- return (new mul(vp, oc, do_index_renaming))->setflag(status_flags::dynallocated);
+ return (new mul(std::move(vp), oc, do_index_renaming))->setflag(status_flags::dynallocated);
}
expair mul::split_ex_to_pair(const ex & e) const
const bool skip_idx_rename = !(options & expand_options::expand_rename_idx);
// First, expand the children
- std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
- const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
+ epvector expanded = expandchildren(options);
+ const epvector & expanded_seq = (expanded.empty() ? seq : expanded);
// Now, look for all the factors that are sums and multiply each one out
// with the next one that is found while collecting the factors which are
* to allow for early cancellations and thus safe memory.
*
* @see mul::expand()
- * @return pointer to epvector containing expanded representation or zero
- * pointer, if sequence is unchanged. */
-std::auto_ptr<epvector> mul::expandchildren(unsigned options) const
+ * @return epvector containing expanded pairs, empty if no members
+ * had to be changed. */
+epvector mul::expandchildren(unsigned options) const
{
const epvector::const_iterator last = seq.end();
epvector::const_iterator cit = seq.begin();
if (!are_ex_trivially_equal(factor,expanded_factor)) {
// something changed, copy seq, eval and return it
- std::auto_ptr<epvector> s(new epvector);
- s->reserve(seq.size());
+ epvector s;
+ s.reserve(seq.size());
// copy parts of seq which are known not to have changed
epvector::const_iterator cit2 = seq.begin();
while (cit2!=cit) {
- s->push_back(*cit2);
+ s.push_back(*cit2);
++cit2;
}
// copy first changed element
- s->push_back(split_ex_to_pair(expanded_factor));
+ s.push_back(split_ex_to_pair(expanded_factor));
++cit2;
// copy rest
while (cit2!=last) {
- s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit2).expand(options)));
+ s.push_back(split_ex_to_pair(recombine_pair_to_ex(*cit2).expand(options)));
++cit2;
}
return s;
}
++cit;
}
-
- return std::auto_ptr<epvector>(0); // nothing has changed
+
+ return epvector(); // nothing has changed
}
GINAC_BIND_UNARCHIVER(mul);
mul(const exvector & v);
mul(const epvector & v);
mul(const epvector & v, const ex & oc, bool do_index_renaming = false);
- mul(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false);
+ mul(epvector && vp, const ex & oc, bool do_index_renaming = false);
mul(const ex & lh, const ex & mh, const ex & rh);
// functions overriding virtual functions from base classes
unsigned return_type() const;
return_type_t return_type_tinfo() const;
ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
- ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
+ ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) const;
expair split_ex_to_pair(const ex & e) const;
expair combine_ex_with_coeff_to_pair(const ex & e, const ex & c) const;
expair combine_pair_with_coeff_to_pair(const expair & p, const ex & c) const;
void do_print_csrc(const print_csrc & c, unsigned level) const;
void do_print_python_repr(const print_python_repr & c, unsigned level) const;
static bool can_be_further_expanded(const ex & e);
- std::auto_ptr<epvector> expandchildren(unsigned options) const;
+ epvector expandchildren(unsigned options) const;
};
GINAC_DECLARE_UNARCHIVER(mul);
{
}
-ncmul::ncmul(std::auto_ptr<exvector> vp) : inherited(vp)
+ncmul::ncmul(exvector && v) : inherited(std::move(v))
{
}
ex ncmul::expand(unsigned options) const
{
// First, expand the children
- std::auto_ptr<exvector> vp = expandchildren(options);
- const exvector &expanded_seq = vp.get() ? *vp : this->seq;
+ exvector v = expandchildren(options);
+ const exvector &expanded_seq = v.empty() ? this->seq : v;
// Now, look for all the factors that are sums and remember their
// position and number of terms.
// If there are no sums, we are done
if (number_of_adds == 0) {
- if (vp.get())
- return (new ncmul(vp))->
+ if (!v.empty())
+ return (new ncmul(std::move(v)))->
setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
else
return *this;
ex ncmul::evalm() const
{
// Evaluate children first
- std::auto_ptr<exvector> s(new exvector);
- s->reserve(seq.size());
+ exvector s;
+ s.reserve(seq.size());
exvector::const_iterator it = seq.begin(), itend = seq.end();
while (it != itend) {
- s->push_back(it->evalm());
+ s.push_back(it->evalm());
it++;
}
// If there are only matrices, simply multiply them
- it = s->begin(); itend = s->end();
+ it = s.begin(); itend = s.end();
if (is_a<matrix>(*it)) {
matrix prod(ex_to<matrix>(*it));
it++;
}
no_matrix:
- return (new ncmul(s))->setflag(status_flags::dynallocated);
+ return (new ncmul(std::move(s)))->setflag(status_flags::dynallocated);
}
ex ncmul::thiscontainer(const exvector & v) const
return (new ncmul(v))->setflag(status_flags::dynallocated);
}
-ex ncmul::thiscontainer(std::auto_ptr<exvector> vp) const
+ex ncmul::thiscontainer(exvector && v) const
{
- return (new ncmul(vp))->setflag(status_flags::dynallocated);
+ return (new ncmul(std::move(v)))->setflag(status_flags::dynallocated);
}
ex ncmul::conjugate() const
// non-virtual functions in this class
//////////
-std::auto_ptr<exvector> ncmul::expandchildren(unsigned options) const
+exvector ncmul::expandchildren(unsigned options) const
{
const_iterator cit = this->seq.begin(), end = this->seq.end();
while (cit != end) {
if (!are_ex_trivially_equal(*cit, expanded_ex)) {
// copy first part of seq which hasn't changed
- std::auto_ptr<exvector> s(new exvector(this->seq.begin(), cit));
- reserve(*s, this->seq.size());
+ exvector s(this->seq.begin(), cit);
+ s.reserve(this->seq.size());
// insert changed element
- s->push_back(expanded_ex);
+ s.push_back(expanded_ex);
++cit;
// copy rest
while (cit != end) {
- s->push_back(cit->expand(options));
+ s.push_back(cit->expand(options));
++cit;
}
++cit;
}
- return std::auto_ptr<exvector>(0); // nothing has changed
+ return exvector(); // nothing has changed
}
const exvector & ncmul::get_factors() const
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(std::auto_ptr<exvector> vp);
+ ncmul(exvector && v);
// functions overriding virtual functions from base classes
public:
ex evalm() const;
exvector get_free_indices() const;
ex thiscontainer(const exvector & v) const;
- ex thiscontainer(std::auto_ptr<exvector> vp) const;
+ ex thiscontainer(exvector && v) const;
ex conjugate() const;
ex real_part() const;
ex imag_part() const;
void do_print_csrc(const print_context & c, unsigned level) const;
size_t count_factors(const ex & e) const;
void append_factors(exvector & v, const ex & e) const;
- std::auto_ptr<exvector> expandchildren(unsigned options) const;
+ exvector expandchildren(unsigned options) const;
public:
const exvector & get_factors() const;
};
}
ex oc = overall_coeff.to_rational(repl);
if (oc.info(info_flags::numeric))
- return thisexpairseq(s, overall_coeff);
+ return thisexpairseq(std::move(s), overall_coeff);
else
s.push_back(combine_ex_with_coeff_to_pair(oc, _ex1));
- return thisexpairseq(s, default_overall_coeff());
+ return thisexpairseq(std::move(s), default_overall_coeff());
}
/** Implementation of ex::to_polynomial() for expairseqs. */
}
ex oc = overall_coeff.to_polynomial(repl);
if (oc.info(info_flags::numeric))
- return thisexpairseq(s, overall_coeff);
+ return thisexpairseq(std::move(s), overall_coeff);
else
s.push_back(combine_ex_with_coeff_to_pair(oc, _ex1));
- return thisexpairseq(s, default_overall_coeff());
+ return thisexpairseq(std::move(s), default_overall_coeff());
}
* implements the actual function call. */
class print_functor {
public:
- print_functor() : impl(0) {}
+ print_functor() : impl(nullptr) {}
print_functor(const print_functor & other) : impl(other.impl.get() ? other.impl->duplicate() : 0) {}
- print_functor(std::auto_ptr<print_functor_impl> impl_) : impl(impl_) {}
+ print_functor(std::unique_ptr<print_functor_impl> impl_) : impl(std::move(impl_)) {}
template <class T, class C>
print_functor(void f(const T &, const C &, unsigned)) : impl(new print_ptrfun_handler<T, C>(f)) {}
bool is_valid() const { return impl.get(); }
private:
- std::auto_ptr<print_functor_impl> impl;
+ std::unique_ptr<print_functor_impl> impl;
};