Boost logo

Boost :

From: Vladimir Batov (batov_at_[hidden])
Date: 2007-10-05 12:39:10


Given I've been using this Pimpl idiom quite extensively lately I've noticed
writing the same scaffolding over and over again. Being the lazy bugger as I
am I looked around if there was anything available. Turns out there were
proposals floated around (like Asger Mangaard's dated around May 2006).
However, I did not see anything that would preserve idiom's original
purpose/value - the separation of interface and implementation. So, I jogged
something with that in mind. That seemed to do the job for me as something
tedious like

class Test
{
    public:

    Test (int);
    Test (int, int);

    int get() const;

    bool operator==(Test const& p) const { return impl_ == p.impl_; }
    bool operator!=(Test const& p) const { return impl_ != p.impl_; }
    operator bool() const { return implementation_; }

    void swap(pimpl& that) { impl_.swap(that.impl_); }

    private:

    struct Internal;
    boost::shared_ptr<Internal> impl_;
};

shrunk down do pure interface

struct Test : public boost::pimpl<Test>
{
    Test (int);
    Test (int, int);

    int get() const;
};

with implementation details safely tacked away in an implementation file.
However, it looked suspiciously easy. So, I am throwing it out for all the
respected community to see (uploaded as vb_pimpl_0.1.zip) and to set me
straight. Is there any value in that basic idea? Don't hold back your
criticism.

Regards,
Vladimir.


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