|
Boost : |
From: David Abrahams (abrahams_at_[hidden])
Date: 1998-12-07 17:11:55
Beman Dawes (beman_at_[hidden]) wrote:
>I
>don't have any problem requiring the specific name (say "use_count")
>for the embedded counter.
I do: It could cause unneccessary collisions and unintended effects!
It's so easy to use base class; why not do it that way?
namespace boost {
template <class T = std::size_t>
struct reference_counted {
T use_count;
};
template <class T, class RC = std::size_t >
class embedded_ptr
{
...
private:
// All reference count manipulations go thru this member function
inline RC& count() const
{
reference_counted<RC>& counted = *this->p;
return counted.use_count;
}
};
}
Intrusively reference-counted classes would then inherit publicly from
boost::reference_counted<>.
-Dave
P.S. If you don't like the 2nd optional argument from embedded_ptr for
types that want a different reference count type, we could ask the user
to specialize boost::reference_counted_traits<> for their
intrusively-counted types, supplying a count_type.
--------------------------------------------------------------
David Abrahams * Mark of the Unicorn, Inc. * abrahams_at_[hidden]
------------------------------------------------------------------------
Free Web-based e-mail groups -- http://www.eGroups.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk