|
Boost Users : |
From: Bruno Martínez (br1_at_[hidden])
Date: 2005-11-28 07:34:54
On Mon, 28 Nov 2005 06:57:07 -0200, Daniel Krügler <dsp_at_[hidden]> wrote:
> Bruno Martínez wrote:
>> On Thu, 24 Nov 2005 07:10:41 -0200, Daniel Krügler <dsp_at_[hidden]> wrote:
>>
>>
>>> Bruno Martínez wrote:
>>>
>>>
>>>> I know. The problem is that I want incomplete types support *and*
>>>> release
>>>> member function.
>>>
>>> Use std::auto_ptr and ensure that you obey Peter Dimov's
>>> recommendations. I know, that the standard says, in 5.3.5
>>>
>>> "If the object being deleted has incomplete class type at the point of
>>> deletion and the complete class has a
>>> non-trivial destructor or a deallocation function, the behavior is
>>> undefined."
>>>
>>> and in 17.4.3.6
>>>
>>> "if an incomplete type (3.9) is used as a template argument when
>>> instantiating a template component."
>>>
>>> There exists no special restriction on std::auto_ptr for incomplete
>>> classes
>>
>>
>> I don't understand. There is a restriction. It's 17.4.3.6!
>
> OK, so you have to write your own auto_ptr or move_ptr.
>
> From a legal point of view, you can't use auto_ptr for incomplete
> classes, from a practical point of view you can do that provided that
> some rules concerning d'tor definition are obeyed.
Yes, that's it. This conclusion is the one I think should be added to the
FAQ.
>> #include <boost/scoped_ptr.hpp>
>>
>> struct node {
>> boost::scoped_ptr<node> next;
>> node(node* next = 0) : next(next) {}
>> };
>>
>> int main()
>> {
>> node n;
>> n.next.reset(new node);
>> }
>
> I wasn't carefully reading your code, obviously ;-) It works, because at
> the point of the destructor of next the hosting class node is completely
> defined. You have a special case here, not the classical pimpl problem:
>
> struct A {
> struct Impl;
> boost::scoped_ptr<Impl> pimpl;
> };
>
> because of your next member referencing the hosting class itself.
> In the A case pimpl's d'tor does not have the complete definition of
> Impl available, in contrast to your node class.
Yes, it's not exactly the same.
Bruno
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net