$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] Pimpl Again?
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2016-05-31 21:08:10
On May 31, 2016, at 8:50 PM, Vladimir Batov <Vladimir.Batov_at_[hidden]> wrote:
> 
> 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.
No apologies necessary.  I donât think anyone interprets this as degrading unique_ptr.  Everything you say is correct, except for this one little detail: :-)
> 
> 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?
Perhaps I wasnât clear:
It has to be outlined, in the source.cpp:
    #include <memory>
    class Book
    {
        struct implementation;
        std::unique_ptr<implementation> impl_;
    public:
        ~Book();
        Book();
    };
    int
    main()
    {
        Book b;
    }
    struct Book::implementation
    {
    };
    Book::~Book() = default;
    Book::Book() = default;
It is ok to *define* a special member with â= defaultâ in the source.  It is only this tiny misunderstanding I would like to clear up.  I agree with you that because of the need to do this outlining there is room for a pimpl toolbox here.
Howard