Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 1998-12-07 17:11:55

Beman Dawes (beman_at_[hidden]) wrote:

>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
  // 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


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 --

Boost list run by bdawes at, gregod at, cpdaniel at, john at