Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-10-08 05:39:16

"Jonathan Turkanis" <technews_at_[hidden]> wrote
> "Andy Little" <andy_at_[hidden]> wrote
> > Hi,
> >
> > Any interest in a shared_object?
> I have no idea what you mean, but I'll be posting something called
> soon.

I guess what I am after is:

 shared_object<T> my_obj; // Now my_obj refers to a T, which I can access
by reference.
//Various ctors:
   shared_object<T1> my_obj1(a,b,c);
   shared_object<T2> my_obj2 = my_obj1;
   my_obj = my_obj1; // assume T is (say) a base of T1.
//compare etc
   my_obj == my_obj1;

Reference gives a different guarantee than pointers. Ok Could still be cast
to a pointer but ....

  T& x = my_obj(); // reference *feels* like more obvious semantics than

*Ideally* my_obj always holds something... never empty. That is I guess
problematic from the implementation viewpoint, as it may cause a large
number of allocations. However it makes the thing extremely simple to use.
Dont really want to have to do this all the time:

    if( !my_obj.is_empty()){

OTOH maybe could do:
share_object<T> my_empty_obj(leave_empty());
// then make sure its not empty before going public...

As to implementation. Maybe slow.. maybe big, but typically what I would
want it for is for say switching views in a GUI app. Not critical on speed
or size. shared_object probably implements a garbage collector in fact.

> > In this case its the object that is shared, not the pointer....

> With shared_ptr, the object, not the pointer, is shared.

Aha ... descriptively named then... ;-)

Andy Little

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