Boost logo

Boost :

Subject: Re: [boost] [pimpl] Mini Review
From: Sergiu Dotenco (sergiu.dotenco_at_[hidden])
Date: 2011-05-26 11:37:52


Am 26.05.2011 11:22, schrieb Artyom Beilis:
> The only advantage I can see in boost.pimpl over scoped_ptr or auto_ptr
> is that it does not require explicit destructor.
>
> i.e.
>
>
> class Foo : boost::noncopyable {
> public:
> Foo();
> int x() const;
> void x(int v);
> private:
> struct data;
> std::auto_ptr<data> d;
> };
>
> No good. You need to add
>
> ~Foo();
>
> So it would know to destroy Foo::Data correctly.

You can't use std::auto_ptr for pimpl implementation in portable code.
Doing so is undefined behavior. To quote ISO/IEC 14882:2003 (§17.4.3.6,
p. 329):

"In particular, the effects are undefined in the following cases:
[...]
— if an incomplete type (3.9) is used as a template argument when
  instantiating a template component, unless specifically allowed
  for that component."

which applies to most standard library types.


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