« Return to Thread: RFC - lifetime management

Re: RFC - lifetime management

by Martin Schulz-3 :: Rate this Message:

Reply to Author | View in Thread


> For classes with loads of RAII object members, usage could
> look like this:
>
>   class Foo {
>     Foo()  {
>       keep_alive_.put(new RAIIBar(...));
>       keep_alive_.put(new RAIIWhatever(...));
>     }
>   private:
>     heap keep_alive_;
>   };

To me, that sounds very much like a std::vector<boost:shared_ptr<void>
>:

  typedef std::vector<boost::shared_ptr<void> > heap;

  class Foo {
    Foo()  {
      keep_alive_.push_back(boost::shared_ptr<RAIIBar>(new
RAIIBar(...)));
      keep_alive_.push_back(boost::shared_ptr<RAIIWhatever>(new
RAIIWhatever(...)));
    }
  private:
    heap keep_alive_;
  };

Does this do what you intended?

With a bit of syntactic sugar, it would be possible to avoid the
intermediate shared_ptr type, probably. I consider all real work already
done.

> Support should be added for putting shared_ptrs and
> auto_ptrs.

You get this for free with the above.

> I have a wide variety of naming suggestions and an
> extended interface for premature deletion but I'll save those
> for a later post.

keep_alive_.erase(keep_alive_.begin()+n);

Should do that. Again, some syntactic sugar might help.



Is that what you thought about?

Yours,
        Martin.

--
Dr. Martin Schulz (schulz@...)
Software Engineer
Synopsys GmbH
Karl-Hammerschmidt-Str. 34
D-85609 Dornach, Germany
Munich office: +49 (89) 993-20203
Home office:   +49 (721) 6099511
http://www.synopsys.com
 
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

 « Return to Thread: RFC - lifetime management