Boost logo

Boost :

Subject: Re: [boost] [pimpl] No documentation for pointer semantics
From: Vladimir Batov (vb.mail.247_at_[hidden])
Date: 2014-06-07 05:43:14


Vladimir Batov wrote
>
> Rob Stewart-6 wrote
>> On June 6, 2014 8:02:44 AM EDT, Vladimir Batov wrote:
>>>Rob Stewart-6 wrote
>>>> ...
>>>>> On June 6, 2014 4:59:47 AM EDT, Vladimir Batov wrote:
>>>>>... my offering of pimpl::pointer_semantics and
>>>>>pimpl::value_semantics seems to make sense.
>>>>
>>>> That's the problem. It isn't the Pimpl Idiom anymore.
>>>
>>>... it seems my "extended"
>>>interpretation of Pimpl to still be the Pimpl Idiom. :-) First, Pimpl
>>>== Handle/Body == Bridge.
>> ...
>> I don't accept the assertion. That is, the Pimpl Idiom is the degenerate
>> case, but it isn't the same as the Bridge Pattern.
> ...
> Here we have no choice but go and ask H. Sutter as it was him who
> popularized Pimpl and wrote quite a bit about it.
>
> 1) http://www.gotw.ca/publications/mill04.htm
> 2) http://www.gotw.ca/publications/mill05.htm#1
> 3) http://herbsutter.com/gotw/_101/
>
> In #1 Sutter introduces Pimpl as "a special form of the handle/body idiom
> (what I call the Pimpl Idiom...";
> Then in #2 he reiterates again that "This is a variant of the handle/body
> idiom."
> ...
> When I read Sutter's later writings on that topic (and I see you
> participating in the conversations), ...

Reading Sutter's http://herbsutter.com/gotw/_100 I conclude that he is not
of much help to resolve the matter. First he writes:

> Class widget uses a variant of the handle/body idiom. As documented by
> Coplien [1], handle/body was described as being primarily useful for
> reference counting of a shared implementation, but it also has more
> general implementation-hiding uses. For convenience, from now on I’ll call
> widget the “visible class” and impl the “Pimpl class.” [2] One big
> advantage of this idiom is that it breaks compile-time dependencies...
> it’s often dubbed a “compilation firewall.”

To me it reads "it's another application of the handle/body idiom but we
focus on its other property so we call it pimpl". Then though Sutter
indicates that:

> Prefer to hold the Pimpl using a unique_ptr. It’s more efficient than
> using a shared_ptr, and correctly expresses the intent that
*
> the Pimpl object should not be shared.
*

which is clearly a departure from the generic handle/body idiom. I suspect
it is due to Sutter being too much of an educator here rather than actual
developer (who would realize that sometimes Pimpl object needs to be
shared).

That said, I glanced over his pimpl::value_semantics generalization at
http://herbsutter.com/gotw/_101/ and my first impression is quite positive.
It's very lightweight and I find splitting one header in two (public and
private) to be very sensible (ironically matching the handle/body concept).
I myself routinely do that to implement pimpl-based hierarchies. In
comparison my-pimpl offering looks quite heavy and old (given no C++11
facelift). More and more I feel my-pimpl is a few years late to the party,
err... the review.

 

--
View this message in context: http://boost.2283326.n4.nabble.com/pimpl-No-documentation-for-pointer-semantics-tp4663510p4663657.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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