Topic: Where can I find destructor of the template shared_ptr?


Author: "hzhuo1@gmail.com" <hzhuo1@gmail.com>
Date: Wed, 12 Jul 2006 10:20:51 CST
Raw View
In the standard C++ TR1 draft, I find the following regulation:

2.2.3.2 shared_ptr destructor
~shared_ptr();
1 Effects:
- If *this is empty, there are no side effects.
- If *this shares ownership with another shared_ptr instance
(use_count() >
1), decrements that instance's
use count.
- Otherwise, if *this owns a pointer p and a deleter d, d(p) is
called.
- Otherwise, *this owns a pointer p, and delete p is called.
2 Throws: nothing.

But when I refer to shared_ptr.hpp implemented by Boost,I can't find
any destructors of shared_ptr.Who can tell me how it is implemented?I
will be appreciative.

The library Boost can be downloaded as a .zip file at the following
webpage:
http://sourceforge.net/project/showfiles.php?group_id=7586
And the webpage of Boost is http://boost.sourceforge.net/.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Richard Smith" <richard@ex-parrot.com>
Date: Wed, 12 Jul 2006 12:55:16 CST
Raw View
hzhuo1@gmail.com wrote:
> In the standard C++ TR1 draft, I find the following regulation:
>
[...]
>
> But when I refer to shared_ptr.hpp implemented by Boost,I can't find
> any destructors of shared_ptr.

The compiler generated implentation does the right thing -- it calls
the destructor on each member and one of these (specifically, the
detail::shared_count member) does the action described in your quote
from TR1.

>Who can tell me how it is implemented?I

Have a look in boost/detail/shared_count.hpp.  But if you just want to
know what it does, rather than how it does it, it does what the boost
and/or TR1 documentation says it does.

--
Richard Smith

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]