X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Ffunction.cppy;h=0876f9cf955bfabe56154554c96eaef0b6e31f12;hp=dba9f4e0f096b8234234e540c109484ebdf260f8;hb=d5b86dd10dd9cba12175d07af0b6edfc9a215e36;hpb=aa2485821e68ea5f627d5753b41245a4cbd62fe3 diff --git a/ginac/function.cppy b/ginac/function.cppy index dba9f4e0..0876f9cf 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -34,7 +34,6 @@ #include "power.h" #include "archive.h" #include "inifcns.h" -#include "tostring.h" #include "utils.h" #include "hash_seed.h" #include "remember.h" @@ -79,7 +78,7 @@ void function_options::initialize() set_name("unnamed_function", "\\\\mbox{unnamed}"); nparams = 0; eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = expand_f - = derivative_f = expl_derivative_f = power_f = series_f = 0; + = derivative_f = expl_derivative_f = power_f = series_f = nullptr; info_f = 0; evalf_params_first = true; use_return_type = false; @@ -242,13 +241,13 @@ 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) { } -function::function(unsigned ser, std::auto_ptr vp) - : exprseq(vp), serial(ser) +function::function(unsigned ser, exvector && v) + : exprseq(std::move(v)), serial(ser) { } @@ -264,13 +263,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::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 @@ -304,7 +302,7 @@ void function::print(const print_context & c, unsigned level) const next_context: unsigned id = pc_info->options.get_id(); - if (id >= pdt.size() || pdt[id] == NULL) { + if (id >= pdt.size() || pdt[id] == nullptr) { // Method not found, try parent print_context class const print_context_class_info *parent_pc_info = pc_info->get_parent(); @@ -387,7 +385,7 @@ ex function::eval(int level) const } } - if (opt.eval_f==0) { + if (opt.eval_f==nullptr) { return this->hold(); } @@ -431,10 +429,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)); } } @@ -485,9 +481,9 @@ ex function::thiscontainer(const exvector & v) const return function(serial, v); } -ex function::thiscontainer(std::auto_ptr vp) const +ex function::thiscontainer(exvector && v) const { - return function(serial, vp); + return function(serial, std::move(v)); } /** Implementation of ex::series for functions. @@ -735,22 +731,22 @@ ex function::pderivative(unsigned diff_param) const // partial differentiation GINAC_ASSERT(serialsetflag(status_flags::dynallocated | - status_flags::evaluated); - - current_serial = serial; - if (opt.power_use_exvector_args) - return ((power_funcp_exvector)(opt.power_f))(seq, power_param); - switch (opt.nparams) { - // the following lines have been generated for max. @maxargs@ parameters + if (opt.power_f) { + // Invoke the defined power function. + current_serial = serial; + if (opt.power_use_exvector_args) + return ((power_funcp_exvector)(opt.power_f))(seq, power_param); + switch (opt.nparams) { + // the following lines have been generated for max. @maxargs@ parameters +++ for N in range(1, maxargs + 1): - case @N@: - return ((power_funcp_@N@)(opt.power_f))(@seq('seq[%(n)d]', N, 0)@, power_param); + case @N@: + return ((power_funcp_@N@)(opt.power_f))(@seq('seq[%(n)d]', N, 0)@, power_param); --- - // end of generated lines + // end of generated lines + } } - throw(std::logic_error("function::power(): no power function defined")); + // No power function defined? Fall back to returning a power object. + return (new GiNaC::power(*this, power_param))->setflag(status_flags::dynallocated | + status_flags::evaluated); } ex function::expand(unsigned options) const @@ -803,27 +801,25 @@ ex function::expand(unsigned options) const GINAC_ASSERT(serial & function::registered_functions() @@ -875,15 +871,13 @@ 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::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")); + throw (std::runtime_error("no function '" + name + "' with " + std::to_string(nparams) + " parameters defined")); } /** Return the print name of the function. */