Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-05-18 06:03:24


Jean-François Brouillet wrote:

>> http://boost.org/libs/smart_ptr/intrusive_ptr.html#constructors
>
>
> The above link only has this to say:
>
>> constructors
>>
>> intrusive_ptr(); // never throws
>> Postconditions: get() == 0.
>>
>> Throws: nothing.
>>
>> intrusive_ptr(T * p, bool add_ref = true);
>> Effects: if(p != 0 && add_ref) intrusive_ptr_add_ref(p);.
>>
>> Postconditions: get() == p.

[...]

Right, so you can't call it a bug if the implementation does exactly as
stated. ;-)

> That settles it then.
>
> I just cannot use intrusive_ptr. Since shared_ptr is already
> ruled out, well .... roll-my-own-time, I guess ...
>
> Too bad for my use of boost.

<shrug>

I'm pretty sure that a shared_ptr-based port can closely approximate the
original, but a custom smart pointer would probably be a better choice for
idiomatic Java code.

As for intrusive_ptr, its main strength is that it has the size of a
pointer. Adding a boolean would likely meet serious opposition.

Your requirements are very interesting, however, and point to a
shared/intrusive hybrid along the lines of:

template<class T> class intrusive_ptr_2
{
    T * px_;
    intrusive_ptr<Object> pn_;

    // insert smart pointer boilerplate here ;-)
};

It's an intrusive pointer that's close to shared_ptr in expressive power;
you can use it to point to a subobject, for example.

Extending intrusive_ptr to accommodate the above along the lines of

template<class T, class U = void> class intrusive_ptr
{
    T * px_;
    U * pn_; // not present when U == void
};

could be feasible.


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