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
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;
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())
{
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
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);
}
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);
}
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
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
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;
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;
}
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)
{
}
}
| 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;}
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];
}