Boost logo

Boost :

From: Asger Mangaard (tmb_at_[hidden])
Date: 2005-09-27 10:12:38

> Could you be more specific as to what functionality such a library would
> supply? If you already have an implementation then an example of it's use
> would be interesting.
> It is my understanding that the pimpl idiom is fairly simple yet also
> class
> specific. I currently implement it like this:
> In the .hpp
> class foo
> {
> ....
> private:
> class pimpl_t;
> pimpl_t* pimpl;
> };
> in the .cpp
> #incldue "foo.hpp"
> class foo::pimpl_t
> {
> public:
> //private data
> };
> I don't readily see how this could be abstracted, so an example would help
> me to see what you are proposing more clearly.

The implementation is simple indeed. However, I find myself using it all
the time.

The only thing my library does is to initialize the forward declared
class, using heap or static memory through policies. Also, provides an
easy way of accessing the data.



boost::pimpl<struct CMyData> m_MyData;


struct CMyData
  : m_Integer(0)
  int m_Integer;

/// Data access
m_MyData->m_Integer = 2341;

The CMyData will be initialized the first time its data members are accessed.

Asger Mangaard

Boost list run by bdawes at, gregod at, cpdaniel at, john at