Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-09-05 10:21:50


Larry Evans wrote:

> Philippe A. Bouchard wrote:
>
>>
>>
>>I'll start by adding a "forced" destruction member. It will decrement the
>>pointer, followed by a self-destruct placed_ptr call. This way at least
>>the programmer will be able to free his own cyclic container.
>>
>>... or maybe operator delete could be displaced for placed_ptr<> or other
>>rc pointer types. What do you think?
>>
> I don't understand. Could you provide examples?

operator delete will not work (too bad for cleanliness) but we could add
the following (dummy example):

void placed_ptr<T>::force_reset(element_type * a_p = 0)
{
        if (m_ptr)
        {
                get_count() = -1; // -1 for cyclic pointer prevention
                get()->~T(); // This will eventually delete the cyclic pointer
                ::free(m_ptr - ...);
        }

        m_ptr = a_p;
}

void placed_ptr<T>::reset(element_type * a_p = 0)
{
        if (m_ptr && (get_count() != -1 && ! -- get_count()))
        {
                get()->~T(); // This will eventually delete the cyclic pointer
                ::free(m_ptr - ...);
        }

        m_ptr = a_p;
}

-- 
Philippe A. Bouchard

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk