Need a cloning smart pointer

H

Hendrik Schober

Hi,

I need something like this:

class X {
private:
struct Impl_ {
virtual ~Impl_() {}
virtual Impl_* clone() const = 0;
};
Impl_* impl_;
public:
// ...
};

'X' should have value semantics, so '*impl_'
must be cloned when 'X' is copied. I know
how to do this and I have don it a couple
of times. And that is bothering me. I would
rather have a smart pointer that supports
cloning semantics and use this whenever I
run into this pattern.
Is there a smart pointer out there doing
this or do I have to roll my own?
Note: Ideally, it would come in just one
header file. I do not want to add a whole
new library to get s cloning smart pointer.

I have full control over 'X' and 'X::Impl',
so I could actually make them fit some ready-
made smart pointer if I find one.

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
 
S

Steve McLellan

Check out the boost libraries, they've got a boost::shared_ptr and
boost::scoped_ptr which are both smart pointers. The shared_ptr includes
reference counting and all that nice stuff. The boost libs in general are
extremely good for a lot of stuff.

Steve
 
H

Hendrik Schober

Steve McLellan said:
Check out the boost libraries, they've got a boost::shared_ptr and
boost::scoped_ptr which are both smart pointers. The shared_ptr includes
reference counting and all that nice stuff. The boost libs in general are
extremely good for a lot of stuff.

That's why we use them.
However, they do not have a cloning
smart pointer.
Steve
Schobi

[...]

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top