Boost logo

Boost :

From: davidbien_at_[hidden]
Date: 2000-04-16 21:38:43

Well, not really, but that what i happened to call them anyway (
misnomer ).

I have written some reference counted object containers, that address
STL containers of reference counted elements from a different
perspective than boost's smart pointer library.

They also support "copy-on-write" functionality ( which is kind of
cool ). This allows keys inserted into sets to have true const-ness -
which is semantically correct.

The conversion-to-pointer is harder to misuse since none of the
reference counted objects are constructable from a pointer.

I also have a polymorphic version that is not demonstrated here.

I would be interested in submitting this for inclusion in your

Here is a usage example, this demonstrates the non-polymorphic

  // This means: garbage collected object using allocator _TyAllocator
  // true: means use int's relational operators
  // false would mean use the address of the object for relationals
  typedef _gco< int, _TyAllocator, true > _TyGcoInt;
  // This means: garbage collected pointer, holding a _TyGcoInt,
  // true: means use copy-on-write, false would mean not.
  typedef _gcp< int, _TyGcoInt, true > _TyGcpInt;
  // This means: garbage collected reference, holding a _TyGcoInt,
  // using copy-on-write:
  typedef _gcr< int, _TyGcoInt, true > _TyGcrInt;

  // A set of "garbage collected" int references:
  typedef set< _TyGcrInt, less< _TyGcrInt >, _TyAllocator > _TySetInt;
  typedef pair< _TySetInt::iterator, bool > _TyPibInt;
  _TySetInt setInts;

  _TyGcrInt gcrInt = 1; // Implicit construction from an int.
  _TyPibInt pibInt = setInts.insert( gcrInt );
  assert( pibInt.second );

  gcrInt = 2; // causes "copy-on-write" to fire.
  pibInt = setInts.insert( gcrInt );
  assert( pibInt.second );

  gcrInt = 3; // causes "copy-on-write"
  pibInt = setInts.insert( gcrInt );
  assert( pibInt.second );

  gcrInt = 2; // copy-on-write
  pibInt = setInts.insert( gcrInt );
  assert( !pibInt.second ); // this was already in the collection.

  // No copy on write on this call - the gcrInt did not
  // get inserted in the set in the last:
  gcrInt = 1;

David Bien

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