Boost logo

Boost :

Subject: Re: [boost] Pimpl Again?
From: Rob Stewart (rstewart_at_[hidden])
Date: 2016-06-01 04:33:16


On May 31, 2016 7:13:53 PM EDT, Emil Dotchevski <emildotchevski_at_[hidden]> wrote:
>On Tue, May 31, 2016 at 4:07 PM, rstewart <rstewart_at_[hidden]> wrote:
>> "Emil Dotchevski" <emildotchevski_at_[hidden]> wrote:
>> > On Tue, May 31, 2016 at 2:45 PM, Rob Stewart <rstewart_at_[hidden]>
>wrote:
>> > > On May 31, 2016 5:10:35 PM EDT, Emil Dotchevski <
>> emildotchevski_at_[hidden]>
>> > > wrote:
>> > > >
>> > > >header:
>> > > >
>> > > >struct foo { int critical_; };
>> > > >shared_ptr<foo> create_foo();
>> > > >inline void use_foo_critical( foo * p ) { ++p->critical_; }
>> > > >void use_foo_not_so_critical( foo * )
>> > >
>> > > Were you leaving encapsulation as an exercise for the reader?
>> > >
>> > > class foo
>> > > {
>> > > public:
>> > > use_critical () { ++critical_; }
>> > > protected:
>> > > int critical_;
>> > > };
>> > >
>> > > Your foo_ can still access critical_.
>> >
>> > Right, though my preference is as follows.
>> >
>> > //Public interface:
>> >
>> > namespace boost { template <class> class shared_ptr; }

You can't do the same thing with std::shared_ptr. Besides, the user of your foo will need the definition of the same shared_ptr as does create_foo(), do you save anything by avoiding the include directive?

>> > class foo;
>> > boost::shared_ptr<foo> create_foo();
>> > void use_foo_critical( foo * );
>> > void use_foo_not_so_critical( foo * );
>> >
>> > //Implementation details:
>> >
>> > class foo
>> > {
>> > foo( foo const & );
>> > foo & operator=( foo const & );
>> > int critical_;
>> > friend void use_foo_critical( foo * );
>> > protected:
>> > foo();
>> > ~foo();
>> > };
>> > inline void use_foo_critical( foo * p ) { ++p->critical_; }
>>
>> That doesn't provide inline access to those with access only to the
>header.
>
>I meant that whole thing being in the header, which is required for
>inline
>access (within the CPP file inline is next to pointless since the
>compiler
>can easily inline any function.) The point I'm making with
>"//implementation details" is that the fact that use_foo_critical is
>defined inline, as well as the exact definition of foo itself, is not
>part
>of the interface and thus subject to change.

As you guessed, I assumed that "Implementation details" referred to code in a separate source file.

Unlike a detail namespace, a mere comment separates users from what you consider implementation details. The compiler can't help you, though I suppose you can implement, in the header, only what needs exposure for performance reasons.

___
Rob

(Sent from my portable computation engine)


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