Boost logo

Boost Users :

Subject: [Boost-users] Pimpl framework comments/suggestions
From: Clinton Mead (clintonmead_at_[hidden])
Date: 2011-04-15 01:32:26


Hi All

I've been experimenting with pimpl recently. What I've seen written about
the pimpl idiom is that you have an interface class and an implementation
class, and in the interface class you put some kind of pointer to the
implementation.

However, I thought, sometimes you might want that to be a shared pointer. Or
an intrusive pointer. Or unique pointer. Or maybe sometimes you might decide
not to use pimpl at all.

I thought it was a bit silly that you had to make these decisions at the
time you create the interface class. I thought it would be nice if you could
write the interface independent of how it was going to be connected to the
implementation, and then hook them together however you like.

So this is what I've done. Basically I've broke things up into three
separate parts:

(1) Interface
(2) Implementation
(3) What joins them together (i've created unique_pimpl and shared_pimpl as
examples)

I've implemented a unique_ptr and shared_ptr pimpl implementations as
examples. The idea is that you can basically do this:

unique_pimpl<interface, impl>::create(...) or
shared_pimpl<interface, impl>::create(...)
make_your_own<interface, impl>::create(...)

for any interface and implementation you choose.

I've included all the code in a question at
http://stackoverflow.com/questions/5666442 but it doesn't seem to be getting
much attention there, so I thought I'd bring it up on this list.

If something like this isn't in Boost, and people like it, with a bit of
help I'd be happy to work on it to get it into Boost. Alternatively I'm
happy for someone else to Boostify this. I've used a bit of c++0x in the
code, gcc 4.4.5 will compile it though.

However if I'm just (badly) reinventing the wheel, if someone could direct
me to where this has already been done that would be good to.

Thanks

Clinton



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net