namespace boost {

namespace tr1 {

template<class T>
struct enable_shared_from_this : boost::enable_shared_from_this
{
    boost::shared_ptr<T> shared_from_this()
    {
        return boost::shared_from_this( _internal_this );
    }

    boost::shared_ptr<T const> shared_from_this() const
    {
        return boost::shared_from_this( const_cast<T const *>( _internal_this ) );
    }

    T* _internal_this;
};

template<class T, class Y> void sp_accept_owner( shared_ptr<Y> * ptr, enable_shared_from_this<T> const * pe, void * /*pd*/ = 0 )
{
    if(pe != 0)
    {
        pe->_internal_this = ptr.get();
    }
    sp_accept_owner( ptr, static_cast< boost::enable_shared_from_this const * >( pe ) );
}

} // namespace tr1

} // namespace boost
