|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-06-23 06:36:27
Gottlob Frege wrote:
> Now I understand that map is a different situation than
> intrusive_ptr - I'm definitely stretching things a bit. But I'm
> looking for reasons to use one technique over the other (and also
> instead of, say, virtual functions / runtime polymorphism, but I
> think I understand most of the differences there). Obviously
> passing in a predicate/policy is the way to go when it is reasonable
> to expect different policies/predicate used *on the same type*, and
> intrusive_ptr is probably a case where different policies don't make
> sense. Is that enough to make it better? ie:
>
> - a policy based add_ref for intrusive_ptr would allow it to be used
> in those rare cases where there is a 'type-overlap' or a 'lack of
> strong typing'
> HOWEVER,
> - a policy based approach would *also* allow different add_refs for
> a single type (ie 'logical' or 'strong' type), which would be
> senseless and *disasterous* when the type really only has one way of
> doing add_ref,
> THUS
> intrusive_ptr chooses free functions, over a policy-based approach
>
> ie we thought about a policy-based approach, but specifically wanted
> to *enforce* one-add_ref-per-type, or
> we didn't even think about it (at least not consciously), it was
> just the natural and obvious thing to do
Well, it really depends on your goals.
If you want to implement the most flexible intrusive_ptr in the world, you
would add an AddRef policy and a Release policy.
If you want to implement *the* intrusive_ptr and specify *the* interface to
implement to make your class X intrusively-countable, you end up with the
current boost::intrusive_ptr.
The upside of the latter approach is that, as usual, you can pass
intrusive_ptr's from library A to library B (without using templates and
putting everything in headers.)
It also gives programmers a standard interface for manipulating the
reference count, if for some reason they need to do that without using
intrusive_ptr.
http://boost.org/libs/smart_ptr/sp_techniques.html#intrusive
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