removed a lot of superfluous const_cast<>()s
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 21 Jun 2001 19:32:57 +0000 (19:32 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 21 Jun 2001 19:32:57 +0000 (19:32 +0000)
ginac/constant.cpp
ginac/container.pl
ginac/matrix.cpp
ginac/numeric.cpp
ginac/power.cpp
ginac/relational.cpp
ginac/structure.pl
ginac/symbol.h
ginsh/ginsh_parser.yy

index 2292385..4ca9492 100644 (file)
@@ -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<constant &>(const_cast<basic &>(other));
-       // return name.compare(o.name);
-       const constant *o = static_cast<const constant *>(&other);
-       if (serial==o->serial) return 0;
-       return serial < o->serial ? -1 : 1;
+       const constant &o = static_cast<const constant &>(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<const constant *>(&other);
-       return serial==o->serial;
+       const constant &o = static_cast<const constant &>(other);
+
+       return serial == o.serial;
 }
 
 unsigned constant::calchash(void) const
index 7b8304b..bed117f 100755 (executable)
@@ -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<basic &>(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<const ${CONTAINER} &>(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<basic &>(other));
-       if (seq.size()!=o.seq.size()) return false;
+       ${CONTAINER} const &o = static_cast<const ${CONTAINER} &>(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;
index 9f9f67a..b133b61 100644 (file)
@@ -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<matrix &>(const_cast<basic &>(other));
+       const matrix & o = static_cast<const matrix &>(other);
        
        // compare number of rows
        if (row != o.rows())
index eb9afa1..b29bf9f 100644 (file)
@@ -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<numeric &>(const_cast<basic &>(*other.bp));
+       const numeric &o = static_cast<const numeric &>(*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<numeric &>(const_cast<basic &>(other));
+       const numeric &o = static_cast<const numeric &>(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<const numeric *>(&other);
+       const numeric &o = static_cast<const numeric &>(other);
        
-       return this->is_equal(*o);
+       return this->is_equal(o);
 }
 
 
index 47efc2f..76c72ac 100644 (file)
@@ -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 power &>(const_cast<basic &>(other));
+       const power &o = static_cast<const power &>(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
index f657f81..88f2ad6 100644 (file)
@@ -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 relational &>(const_cast<basic &>(other));
-       
-       int cmpval;
+       const relational &oth = static_cast<const relational &>(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<oth.o)
-               return -1;
-       else
-               return 1;
+       return (o < oth.o) ? -1 : 1;
 }
 
 unsigned relational::return_type(void) const
index 8b64454..8303dbe 100755 (executable)
@@ -433,8 +433,7 @@ ${subs_statements}
 int ${STRUCTURE}::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
-       ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
-                                                                       (const_cast<basic &>(other));
+       ${STRUCTURE} const &o = static_cast<const ${STRUCTURE} &>(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<basic &>(other));
+       ${STRUCTURE} const &o = static_cast<const ${STRUCTURE} &>(other);
 ${is_equal_statements}
        return true;
 }
index 9bbf3f2..76b8772 100644 (file)
@@ -123,6 +123,11 @@ inline const symbol &ex_to_symbol(const ex &e)
        return static_cast<const symbol &>(*e.bp);
 }
 
+inline symbol &ex_to_nonconst_symbol(const ex &e)
+{
+       return static_cast<symbol &>(*e.bp);
+}
+
 /** Specialization of is_exactly_a<symbol>(obj) for symbol objects. */
 template<> inline bool is_exactly_a<symbol>(const basic & obj)
 {
index 2e51477..98213e2 100644 (file)
@@ -208,7 +208,7 @@ exp : T_NUMBER              {$$ = $1;}
                }
        }
        | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to<numeric>($3).to_int();}
-       | T_SYMBOL '=' exp      {$$ = $3; const_cast<symbol *>(&ex_to<symbol>($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<symbol *>(&ex_to<symbol>(e[0])))->unassign();
+       ex_to_nonconst_symbol(e[0]).unassign();
        return e[0];
 }