Boost logo

Boost :

Subject: Re: [boost] [pimpl] Mini Review
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2011-05-28 13:04:55


On Fri, May 27, 2011 at 9:40 AM, Stewart, Robert <Robert.Stewart_at_[hidden]> wrote:
>
> Given no effect on the interface of a class using Pimpl, where Pimpl can offer real value is in providing predefined policies for how to manage the implementation object and its lifetime.  It could include policies to support things like SBO or cloning (as Artyom has noted).
>

I have/had a SBO "DeplorablePimpl" template (see Herb Sutter's
http://www.gotw.ca/gotw/028.htm). Basically

class X {
    DeplorableImpl<42, XImpl> pimpl;
};

It takes care of most/all of Sutter's concerns. For example, it
checks at compile time (in the cpp file) that sizeof(XImpl) == 42, (or
<= 42, depending on policies) and forces correct constructors, etc.
It does mean that X needs a constructor and destructor to be defined
in the cpp file, not the h file (since the cpp is where XImpl is
known, not just declared).

I'm not sure if this could be incorporated as a policy into a general
Pimpl, or should be kept somewhat separate. Maybe just same namespace
or something.

Tony


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