From d7eee2dd8de4149ff805fd69641316418450275b Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 21 Jun 2001 19:32:57 +0000 Subject: [PATCH] removed a lot of superfluous const_cast<>()s --- ginac/constant.cpp | 16 +++++++++------- ginac/container.pl | 39 ++++++++++++++++++++------------------- ginac/matrix.cpp | 2 +- ginac/numeric.cpp | 8 ++++---- ginac/power.cpp | 11 +++++------ ginac/relational.cpp | 17 ++++++----------- ginac/structure.pl | 6 ++---- ginac/symbol.h | 5 +++++ ginsh/ginsh_parser.yy | 4 ++-- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/ginac/constant.cpp b/ginac/constant.cpp index 22923855..4ca94921 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -191,18 +191,20 @@ ex constant::derivative(const symbol & s) const int constant::compare_same_type(const basic & other) const { GINAC_ASSERT(is_exactly_of_type(other, constant)); - // const constant & o=static_cast(const_cast(other)); - // return name.compare(o.name); - const constant *o = static_cast(&other); - if (serial==o->serial) return 0; - return serial < o->serial ? -1 : 1; + const constant &o = static_cast(other); + + if (serial == o.serial) + return 0; + else + return serial < o.serial ? -1 : 1; } bool constant::is_equal_same_type(const basic & other) const { GINAC_ASSERT(is_exactly_of_type(other, constant)); - const constant *o = static_cast(&other); - return serial==o->serial; + const constant &o = static_cast(other); + + return serial == o.serial; } unsigned constant::calchash(void) const diff --git a/ginac/container.pl b/ginac/container.pl index 7b8304bd..bed117f6 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -467,35 +467,36 @@ ex ${CONTAINER}::subs(const lst & ls, const lst & lr, bool no_pattern) const int ${CONTAINER}::compare_same_type(const basic & other) const { GINAC_ASSERT(is_a<${CONTAINER}>(other)); - ${CONTAINER} const & o=static_cast<${CONTAINER} const &> - (const_cast(other)); - int cmpval; - ${STLT}::const_iterator it1=seq.begin(); - ${STLT}::const_iterator it2=o.seq.begin(); - - for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) { - cmpval=(*it1).compare(*it2); - if (cmpval!=0) return cmpval; - } + ${CONTAINER} const & o = static_cast(other); + + ${STLT}::const_iterator it1 = seq.begin(), it1end = seq.end(), + it2 = o.seq.begin(), it2end = o.seq.end(); - if (it1==seq.end()) { - return (it2==o.seq.end() ? 0 : -1); + while (it1 != it1end && it2 != it2end) { + int cmpval = it1->compare(*it2); + if (cmpval) + return cmpval; + ++it1; ++it2; } - return 1; + return (it1 == it1end) ? (it2 == it2end ? 0 : -1) : 1; } bool ${CONTAINER}::is_equal_same_type(const basic & other) const { GINAC_ASSERT(is_a<${CONTAINER}>(other)); - ${CONTAINER} const & o = static_cast<${CONTAINER} const &>(const_cast(other)); - if (seq.size()!=o.seq.size()) return false; + ${CONTAINER} const &o = static_cast(other); + + if (seq.size() != o.seq.size()) + return false; - ${STLT}::const_iterator it1 = seq.begin(); - ${STLT}::const_iterator it2 = o.seq.begin(); + ${STLT}::const_iterator it1 = seq.begin(), it1end = seq.end(), + it2 = o.seq.begin(); - for (; it1!=seq.end(); ++it1, ++it2) { - if (!(*it1).is_equal(*it2)) return false; + while (it1 != it1end) { + if (!it1->is_equal(*it2)) + return false; + ++it1; ++it2; } return true; diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index 9f9f67a8..b133b616 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -237,7 +237,7 @@ ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const int matrix::compare_same_type(const basic & other) const { GINAC_ASSERT(is_exactly_of_type(other, matrix)); - const matrix & o = static_cast(const_cast(other)); + const matrix & o = static_cast(other); // compare number of rows if (row != o.rows()) diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index eb9afa19..b29bf9f1 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -531,7 +531,7 @@ bool numeric::has(const ex &other) const { if (!is_exactly_of_type(*other.bp, numeric)) return false; - const numeric &o = static_cast(const_cast(*other.bp)); + const numeric &o = static_cast(*other.bp); if (this->is_equal(o) || this->is_equal(-o)) return true; if (o.imag().is_zero()) // e.g. scan for 3 in -3*I @@ -576,7 +576,7 @@ ex numeric::evalf(int level) const int numeric::compare_same_type(const basic &other) const { GINAC_ASSERT(is_exactly_of_type(other, numeric)); - const numeric &o = static_cast(const_cast(other)); + const numeric &o = static_cast(other); return this->compare(o); } @@ -585,9 +585,9 @@ int numeric::compare_same_type(const basic &other) const bool numeric::is_equal_same_type(const basic &other) const { GINAC_ASSERT(is_exactly_of_type(other,numeric)); - const numeric *o = static_cast(&other); + const numeric &o = static_cast(other); - return this->is_equal(*o); + return this->is_equal(o); } diff --git a/ginac/power.cpp b/ginac/power.cpp index 47efc2fd..76c72acc 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -544,14 +544,13 @@ ex power::derivative(const symbol & s) const int power::compare_same_type(const basic & other) const { GINAC_ASSERT(is_exactly_of_type(other, power)); - const power & o=static_cast(const_cast(other)); + const power &o = static_cast(other); - int cmpval; - cmpval=basis.compare(o.basis); - if (cmpval==0) { + int cmpval = basis.compare(o.basis); + if (cmpval) + return cmpval; + else return exponent.compare(o.exponent); - } - return cmpval; } unsigned power::return_type(void) const diff --git a/ginac/relational.cpp b/ginac/relational.cpp index f657f810..88f2ad64 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -193,21 +193,16 @@ ex relational::simplify_ncmul(const exvector & v) const int relational::compare_same_type(const basic & other) const { GINAC_ASSERT(is_exactly_of_type(other, relational)); - const relational & oth=static_cast(const_cast(other)); - - int cmpval; + const relational &oth = static_cast(other); if (o == oth.o) { - cmpval = lh.compare(oth.lh); - if (cmpval==0) - return rh.compare(oth.rh); - else + int cmpval = lh.compare(oth.lh); + if (cmpval) return cmpval; + else + return rh.compare(oth.rh); } - if (o - (const_cast(other)); + ${STRUCTURE} const &o = static_cast(other); int cmpval; ${compare_statements} return 0; @@ -443,8 +442,7 @@ ${compare_statements} bool ${STRUCTURE}::is_equal_same_type(const basic & other) const { GINAC_ASSERT(is_of_type(other,${STRUCTURE})); - ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &> - (const_cast(other)); + ${STRUCTURE} const &o = static_cast(other); ${is_equal_statements} return true; } diff --git a/ginac/symbol.h b/ginac/symbol.h index 9bbf3f2e..76b87720 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -123,6 +123,11 @@ inline const symbol &ex_to_symbol(const ex &e) return static_cast(*e.bp); } +inline symbol &ex_to_nonconst_symbol(const ex &e) +{ + return static_cast(*e.bp); +} + /** Specialization of is_exactly_a(obj) for symbol objects. */ template<> inline bool is_exactly_a(const basic & obj) { diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index 2e514778..98213e25 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -208,7 +208,7 @@ exp : T_NUMBER {$$ = $1;} } } | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to($3).to_int();} - | T_SYMBOL '=' exp {$$ = $3; const_cast(&ex_to($1))->assign($3);} + | T_SYMBOL '=' exp {$$ = $3; ex_to_nonconst_symbol($1).assign($3);} | exp T_EQUAL exp {$$ = $1 == $3;} | exp T_NOTEQ exp {$$ = $1 != $3;} | exp '<' exp {$$ = $1 < $3;} @@ -468,7 +468,7 @@ static ex f_transpose(const exprseq &e) static ex f_unassign(const exprseq &e) { CHECK_ARG(0, symbol, unassign); - (const_cast(&ex_to(e[0])))->unassign(); + ex_to_nonconst_symbol(e[0]).unassign(); return e[0]; } -- 2.44.0