Boost logo

Boost :

From: Kühl, Dietmar (Dietmar.Kuehl_at_[hidden])
Date: 1998-12-07 12:30:58


Hi,

> Yes, it would be nice to be able to write:
>
> shared_ptr<MyClass> my_default_ptr; // direct_shared_ptr
> shared_ptr<MyClass, indirect> my_indirect_shared_ptr;
> shared_ptr<MyClass, embedded> my_embedded_shared_ptr;
>
This is easy to achieve! Here is how:

  // types used to choose the reference counting method:
  struct direct {};
  struct indirected {};
  template <typename T, long T::*count> struct embedded {};

  // declaration of the actual class which is then specialized
  // for the different methods:
  template <typename T, typename method = direct>
  class shared_ptr;

  // finally the various definitions. this is where the interface
  // for the classes is defined. This might involve some
  // redundant typing. However, since the methods are quite
  // different, I think there is only few code to be shared.
  template <typename T>
  class shared_ptr<T, direct> { ... };
  template <typename T>
  class shared_ptr<T, indirect> { ... };
  template <typename T, long T::*count>
  class shared_ptr<T, embedded<T, count> > { ... };

That is, the class 'share_ptr' is simply specialized over the
supported methods. For the methods 'direct' and 'indirect'
it is sufficient to have just some types to identify the method.
For the embedded method I think it is reasonable to have a
way how the user can choose the name of the member. This
is done with the template arguments for the embedded
method.
  
dk
------------------------------------------------------------------------
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