Boost logo

Boost :

From: Jordan DeLong (fracture_at_[hidden])
Date: 2006-02-18 09:53:53


I find myself often writing some boilerplate stuff to make a class
usable and creatable only with shared_ptr's. For example, stuff of
the form:

struct A : private boost::noncopyable {
    static boost::shared_ptr<A> create(int);
    // ...
private:
    explicit A(int);
};

Anyway, I made a little utility to simplify this, which looks like:

struct A : private boost::noncopyable {
    // ...
private:
    friend class shared_new_access;
    explicit A(int);
    ~A(); // only shared_new_access can delete us, also
};

And then later:

boost::shared_ptr<A> pa = shared_new<A>(some_int);

The shared_new function template also works generally as a way to
create new shared_ptr's, since shared_new_access will still have
access to public constructors and destructors also. It also has the
same forwarding problem thing that people have run into when making
auto_ptr_new() or other such utilities.

So anyway: is there any interest in this for boost? It is pretty
small and straight-forward, but I can post an implementation of it to
the vault (or to this list, if that is preferred for something this
small), if there is some interest.

-- 
Jordan DeLong
fracture_at_[hidden]



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