Boost logo

Boost Users :

From: Bill Buklis (boostuser_at_[hidden])
Date: 2007-06-06 14:09:03


For a template class I'd like to add * and -> operators for types that
support it (mainly pointers). However, most instantiations of this class
won't be pointers and therefore these operators won't be valid. I understand
that enable_if can't directly support member functions. But, how can I do
the equivalent of this?

template< typename T >
class Sample
{
    T data;

public:
    Sample( T& data )
        : data(data)
    {
    }
    typename boost::enable_if< boost::is_pointer<T>, T >::type
        operator->() const
    {
        return(data);
    }
    typename boost::enable_if< boost::is_pointer<T>,
        typename boost::remove_pointer<T>::type >::type operator*() const
    {
        return(*data);
    }
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net