Boost logo

Boost :

Subject: [boost] pimpl library proposal
From: Michael Bailey (jinxidoru_at_[hidden])
Date: 2010-12-02 23:54:58


I have created a pimpl library that I use on a regular basis which sits on top of boost and was wondering if there was any interest in my providing it to the community. It is quite simple, but has been extremely useful personally.

The library has two basic components. For starters, it uses a boost::shared_ptr to hide the implementation in the cpp file. The forwarding of the public interface is accomplished through some simple macros. The macros declare each public method, with an appropriate signature, and forward the call onto the implementation class.

It would be easier to show an example of it in action:

my_object.hpp

class my_object
: public boost::pimpl<class my_object_impl>
{
public:
  my_object() {}
  void do_something();
  int do_other_thing( double ) const;
  void lots_of_args( int, int, int, int );
};

my_object.cpp

class my_object_impl
{
public:
  void do_something() {...}
  int do_other_thing( double a1 ) const {...}
  void lots_of_args( int, int, int, int ) {...}
private:
  ...
};

BOOST_PIMPL_CTOR( my_object );
BOOST_PIMPL_METHOD( 0, my_object, do_something );
BOOST_PIMPL_METHOD( 1, my_object, do_other_thing, const );
BOOST_PIMPL_METHOD( 4, my_object, lots_of_args );

If this seems like it would be of any use to others, let me know. I'd be happy to share.


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