/*
 * RetVal is a class template designed to allow the efficient return
 * of class objects from functions (in particular, overloaded
 * operators) that cannot conveniently be told where to write their
 * result.  Essentially, returning a RetVal<T> from a function is
 * exactly like returning a reference to allocated storage, except
 * that the storage will be deallocated at the appropriate time.
 */

template <class T> class RetVal {
public:
     RetVal(const T* tptr);
     ~RefRef();
     operator T&();
     operator T();
protected:
     T* t;
};

template <class T>
RetVal<T>::RetVal(const T* tptr)
{
     t = tptr;
}

template <class T>
RetVal<T>::~RetVal()
{
     delete t;
}

template <class T>
RetVal<T>::operator T&()
{
     return *t;
}

template <class T>
RetVal<T>::operator T()
{
     return *t;
}
