* Wrapper template for making GiNaC classes out of STL containers. */
/*
- * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
inline void container_storage<std::vector>::reserve(std::vector<ex> & v, size_t n) { v.reserve(n); }
-/** Helper template to allow initialization of containers via an overloaded
- * comma operator (idea stolen from Blitz++). */
-template <typename T, typename STLT>
-class container_init {
-public:
- container_init(STLT & s) : stlt(s) {}
-
- container_init<T, STLT> operator,(const T & x)
- {
- stlt.push_back(x);
- return container_init<T, STLT>(stlt);
- }
-
- // The following specializations produce much tighter code than the
- // general case above
-
- container_init<T, STLT> operator,(int x)
- {
- stlt.push_back(x);
- return container_init<T, STLT>(stlt);
- }
-
- container_init<T, STLT> operator,(unsigned int x)
- {
- stlt.push_back(x);
- return container_init<T, STLT>(stlt);
- }
-
- container_init<T, STLT> operator,(long x)
- {
- stlt.push_back(x);
- return container_init<T, STLT>(stlt);
- }
-
- container_init<T, STLT> operator,(unsigned long x)
- {
- stlt.push_back(x);
- return container_init<T, STLT>(stlt);
- }
-
- container_init<T, STLT> operator,(double x)
- {
- stlt.push_back(x);
- return container_init<T, STLT>(stlt);
- }
-
- container_init<T, STLT> operator,(const symbol & x)
- {
- stlt.push_back(T(x));
- return container_init<T, STLT>(stlt);
- }
-
-private:
- container_init();
- STLT & stlt;
-};
-
/** Wrapper template for making GiNaC classes out of STL containers. */
template <template <class T, class = std::allocator<T>> class C>
class container : public basic, public container_storage<C> {
setflag(get_default_flags());
}
- explicit container(const ex & p1) deprecated;
- container(const ex & p1, const ex & p2) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13, const ex & p14) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13, const ex & p14, const ex & p15) deprecated;
- container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13, const ex & p14, const ex & p15, const ex & p16) deprecated;
-
- // First step of initialization of container with a comma-separated
- // sequence of expressions. Subsequent steps are handled by
- // container_init<>::operator,().
- container_init<ex, STLT> operator=(const ex & x) deprecated;
-
// functions overriding virtual functions from base classes
public:
bool info(unsigned inf) const override { return inherited::info(inf); }
size_t nops() const override { return this->seq.size(); }
ex op(size_t i) const override;
ex & let_op(size_t i) override;
- ex eval(int level = 0) const override;
ex subs(const exmap & m, unsigned options = 0) const override;
void read_archive(const archive_node &n, lst &sym_lst) override
inherited::read_archive(n, sym_lst);
setflag(get_default_flags());
- archive_node::archive_node_cit first = n.find_first("seq");
- archive_node::archive_node_cit last = n.find_last("seq");
- ++last;
- this->reserve(this->seq, last - first);
- for (archive_node::archive_node_cit i=first; i<last; ++i) {
+ auto range = n.find_property_range("seq", "seq");
+ this->reserve(this->seq, range.end - range.begin);
+ for (archive_node::archive_node_cit i=range.begin; i<range.end; ++i) {
ex e;
n.find_ex_by_loc(i, e, sym_lst);
- this->seq.push_back(e);
+ this->seq.emplace_back(e);
}
}
void do_print_tree(const print_tree & c, unsigned level) const;
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;
STLT subschildren(const exmap & m, unsigned options = 0) const;
};
setflag(get_default_flags());
}
-/** Deprecatd constructors (prefer initializer list) */
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1)
- : container_storage<C>(1, p1) { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2)
- : container_storage<C>{p1, p2} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3)
- : container_storage<C>{p1, p2, p3} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4)
- : container_storage<C>{p1, p2, p3, p4} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5)
- : container_storage<C>{p1, p2, p3, p4, p5} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6)
- : container_storage<C>{p1, p2, p3, p4, p5, p6} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13, const ex & p14)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13, const ex & p14, const ex & p15)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15} { setflag(get_default_flags()); }
-template <template <class T, class = std::allocator<T>> class C>
-container<C>::container(const ex & p1, const ex & p2, const ex & p3, const ex & p4, const ex & p5, const ex & p6, const ex & p7, const ex & p8,
- const ex & p9, const ex & p10, const ex & p11, const ex & p12, const ex & p13, const ex & p14, const ex & p15, const ex & p16)
- : container_storage<C>{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16} { setflag(get_default_flags()); }
-
-template <template <class T, class = std::allocator<T>> class C>
-container_init<ex, typename container_storage<C>::STLT> container<C>::operator=(const ex & x)
-{
- this->seq.push_back(x);
- return container_init<ex, typename container_storage<C>::STLT>(this->seq);
-}
-
template <template <class T, class = std::allocator<T>> class C>
void container<C>::do_print(const print_context & c, unsigned level) const
{
return *it;
}
-template <template <class T, class = std::allocator<T>> class C>
-ex container<C>::eval(int level) const
-{
- if (level == 1)
- return hold();
- else
- return thiscontainer(evalchildren(level));
-}
-
template <template <class T, class = std::allocator<T>> class C>
ex container<C>::subs(const exmap & m, unsigned options) const
{
c.s << closebracket;
}
-template <template <class T, class = std::allocator<T>> class C>
-typename container<C>::STLT container<C>::evalchildren(int level) const
-{
- if (level == 1)
- return this->seq;
- else if (level == -max_recursion_level)
- throw std::runtime_error("max recursion level reached");
-
- STLT s;
- this->reserve(s, this->seq.size());
-
- --level;
- const_iterator it = this->seq.begin(), itend = this->seq.end();
- while (it != itend) {
- s.push_back(it->eval(level));
- ++it;
- }
-
- return s;
-}
-
template <template <class T, class = std::allocator<T>> class C>
typename container<C>::STLT container<C>::subschildren(const exmap & m, unsigned options) const
{