-/** Check if ex is a handle to a TYPE, not including base classes. */
-#define is_ex_exactly_of_type(OBJ,TYPE) \
- ((*(OBJ).bp).tinfo()==GiNaC::TINFO_##TYPE)
+/** 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.
+ *
+ * @param e expression
+ * @return reference to pseries object
+ * @see is_exactly_a<class T>() */
+template <class T>
+inline const T &ex_to(const ex &e)
+{
+ GINAC_ASSERT(is_a<T>(e));
+ return static_cast<const T &>(*e.bp);
+}