Boost logo

Boost :

From: Martin Schulz (Martin.Schulz_at_[hidden])
Date: 2007-09-18 04:16:49


> 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_at_[hidden])
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
 

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk