|
Boost : |
Subject: Re: [boost] [pimpl] Mini Review
From: Artyom Beilis (artyomtnk_at_[hidden])
Date: 2011-05-26 12:28:11
> From: Sergiu Dotenco <sergiu.dotenco_at_[hidden]>
>
> 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.
When you actually implement Foo::~Foo() {} in cpp file
the type of the data object is complete so the destructor
is installed correctly.
It is undefined if you have inline destructor that does not have
defined "struct data" but it is defined for non-inline destructor in cpp
that has fully defined "struct data"
So there is nothing wrong there neither in reality nor by the standard.
Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.sf.net/
CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk