Boost logo

Boost :

Subject: Re: [boost] Pimpl Again?
From: Vladimir Batov (Vladimir.Batov_at_[hidden])
Date: 2016-05-31 20:50:24


On 2016-06-01 10:25, Howard Hinnant wrote:
> On May 28, 2016, at 10:35 PM, Vladimir Batov
> <Vladimir.Batov_at_[hidden]> wrote:
>>
>> and IMO the proposed design does have advantage over unique_ptr-based
>> pimpl as IMO unique_ptr hardly has any advantage over the raw pointer
>> -- even the destructor has to be explicit non-default and non-inlined.
>
> <nitpick> You keep saying this and it is like fingernails on a
> chalkboard to me. The correct statement is not that far off of what
> you’re saying, and does not invalidate your point.
>
> The unique_ptr-based pimpl has to have an outlined destructor, but it
> can (and should) be defaulted:
>
> Book::~Book() = default;

Howard, my most humble apologies. English is not my first and its
subtleties stubbornly escape me. The least of all I sought to degrade
std::unique_ptr. Truly. Unreservedly. I cringed myself when I read what
I wrote because I left out an important part -- "in pimpl-related
context". And I keep saying those things not because I am trying to
degrade unique_ptr but because IMO unique_ptr was developed for a very
different purpose. It fits the purpose perfectly... it's just not a good
fit for the pimpl idiom... something Sutter suggests in his GotWs over
and over again.

As for

Book::~Book() = default;

I am afraid I have to disagree. I suspect that won't work. Because the
compiler will try to inline ~Book() (i.e. call
unique_ptr<Book::implementation> destructor) and for that
Book::implementation needs to be complete. So, ~Book() even with an
empty body needs to be explicit in the implementation file. Am I right?


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