Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2002-05-03 15:00:19

From: "David B. Held" <dheld_at_[hidden]>

> I would like to see people comment on the various questions:

Here are my opinions on a few random issues:

Yes, I think a policy-based smart pointer is worth pursuing further
but I don't know what the outcome of that investigation will be.

If the idea of a policy-based smart pointer has any merit, it should be
easier to implement a new smart pointer using policies than to implement
the smart pointer from scratch. If that's the case, shared_ptr should
definitely be implemented in terms of the smart_ptr. If it's not, then
forget smart_ptr - we don't need it.

I do wonder if end users should ever write code in terms of smart_ptr.
Perhaps smart_ptr should just be a mechanism for implementing other
named types:

  template< class T >
  class shared_ptr : private smart_ptr<T,etc>
      using smart_ptr<T,etc>::get;

I think too much code gets written for specific cases rather than
the general. For example, many people write streaming operations

   std::ostream &operator<<( std::ostream &os, const MyClass &mc )

instead of

   template< class CharT, class Traits >
   std::basic_ostream<CharT,Traits> &operator<<(
           std::basic_ostream<CharT,Traits> &os, const MyClass &mc )

I'd hate a policy based smart pointer to encourage more of this
behaviour. If smart_ptr is exposed to the general public, I'd fear
they would write

  template< class T >
  void foo( const smart_ptr<T> &p )

instead of

  template< class T, class P1, etc >
  void foo( const smart_ptr<T,P1,etc> &p )

And finally, I'm convinced that shared_ptr's dynamic mechanism for
specifying the deleter is correct. I should be able to write:

shared_array<char> p1( (char*)malloc(100), free );
shared_array<char> p2( new char[200] );
shared_array<char> p3( MyAllocateCharBuff(300), MyFreeCharBuff );
p1 = p2;
p2 = p3;

Why not? A char buffer is a char buffer. How I need to dispose of
it when I've finished with it shouldn't affect its type.

Oh, one more thing - I don't care too much for weak_ptr. I think
the overhead doesn't reflect its (lack of) usefulness. But maybe I
just need to be educated on how to use it... ;-)


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