return e.op(i);
}
-#if 0
- // How do we make this work in the context of the "reference to
- // temporary" problem? Return an auto_ptr?
- pointer operator->() const
+ // This should return an ex*, but that would be a pointer to a
+ // temporary value
+ std::auto_ptr<ex> operator->() const
{
- return &(operator*());
+ return std::auto_ptr<ex>(new ex(operator*()));
}
-#endif
ex operator[](difference_type n) const
{
return r.e.op(r.i);
}
- // operator->() not implemented (see above)
+ std::auto_ptr<ex> operator->() const
+ {
+ return std::auto_ptr<ex>(new ex(operator*()));
+ }
const_preorder_iterator &operator++()
{
return r.e.op(r.i);
}
- // operator->() not implemented
+ std::auto_ptr<ex> operator->() const
+ {
+ return std::auto_ptr<ex>(new ex(operator*()));
+ }
const_postorder_iterator &operator++()
{
/** Return a reference to the basic-derived class T object embedded in an
* expression. This is fast but unsafe: the result is undefined if the
* expression does not contain a T object at its top level. Hence, you
- * should generally check the type of e first.
+ * should generally check the type of e first. Also, you shouldn't cache
+ * the returned reference because GiNaC's garbage collector may destroy
+ * the referenced object any time it's used in another expression.
*
* @param e expression
* @return reference to object of class T