From: Leigh Johnston on
Hi,

N3000 states that an incomplete type is allowed for shared_ptr and
unique_ptr but it doesn't say the same for auto_ptr. Is this omission a
mistake or deliberate?

An incomplete type auto_ptr member variable should be allowed as long as
parent class destructor is not declared inline. This is useful when
implemented pimpl idiom:

struct opaque_type;

struct foo
{
~foo(); // dtor defined elsewhere
std::auto_ptr<opaque_type> pimpl;
};

/Leigh


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Bart van Ingen Schenau on
On Feb 3, 12:08 am, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
> Hi,
>
> N3000 states that an incomplete type is allowed for shared_ptr and
> unique_ptr but it doesn't say the same for auto_ptr. Is this omission a
> mistake or deliberate?

It is probably deliberate.
In the C++03 standard, all types used as template argument for
templates in the standard library have to be complete types.
As there are possibly/probably some library implementations that rely
on the fact that the types must be complete, my guess is that the
standards committee did not want to break these implementations by
allowing incomplete types for already existing templates.

>
> /Leigh
>
Bart v Ingen Schenau


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Walter van der Hee on
On 3 Feb, 00:08, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
> Hi,
>
> N3000 states that an incomplete type is allowed for shared_ptr and
> unique_ptr but it doesn't say the same for auto_ptr. Is this omission a
> mistake or deliberate?
>
> An incomplete type auto_ptr member variable should be allowed as long as
> parent class destructor is not declared inline. This is useful when
> implemented pimpl idiom:
>
> struct opaque_type;
>
> struct foo
> {
> ~foo(); // dtor defined elsewhere
> std::auto_ptr<opaque_type> pimpl;
>
> };
>
> /Leigh
>

Quote from N3000: "The class template auto_ptr is deprecated. [ Note:
The class template unique_ptr (20.8.14) provides a
better solution. �end note ]"

ciao,
Walter


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 3 Feb., 00:08, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
> N3000 states that an incomplete type is allowed for shared_ptr and
> unique_ptr but it doesn't say the same for auto_ptr. Is this omission a
> mistake or deliberate?
>
> An incomplete type auto_ptr member variable should be allowed as long as
> parent class destructor is not declared inline. This is useful when
> implemented pimpl idiom:
>
> struct opaque_type;
>
> struct foo
> {
> ~foo(); // dtor defined elsewhere
> std::auto_ptr<opaque_type> pimpl;
> };

std::auto_ptr is a deprecated component from
C++0x on, it's suggested replacement is
std::unique_ptr.

The design of std::auto_ptr bases essentially
on some obscure rule in C++03, and has some
inherent defects. It seemed to be the best
compromise not to change std::auto_ptr at all
- a correct fix would have removed
std::auto_ptr_ref but this change would have
caused a potential backward-compatibility problem
for those who explicitly did depend on this
template.

The fact that std::auto_ptr_ref was specified
as a normal component (and not kept unspecified)
was another problem of the original spec. This
will be changed for C++0x.

Adding support for incomplete types for auto_ptr
was considered by the committee but the idea
was rejected, because of it's deprecated state.
Any change would have required that existing
implementations need to be changed and in regard
to existing alternatives this seemed not worth
the effort, such a correct specification would
require.

Greetings from Bremen,

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]