shared_ptr now autodetects counted_bases; minor test updates; intrusive_ptr no longer calls addref/release for NULL pointers.

[SVN r13602]
This commit is contained in:
Peter Dimov
2002-05-01 11:22:22 +00:00
parent 11eacab70e
commit 4653c3673b
4 changed files with 52 additions and 12 deletions
+35 -3
View File
@@ -40,7 +40,7 @@ struct X
std::cout << "X(" << this << ")::X()\n";
}
virtual ~X()
~X() // virtual destructor deliberately omitted
{
--cnt;
std::cout << "X(" << this << ")::~X()\n";
@@ -96,6 +96,28 @@ void release_object(int * p)
std::cout << "release_object()\n";
}
class Z: public virtual boost::counted_base
{
public:
Z()
{
++cnt;
std::cout << "Z(" << this << ")::Z()\n";
}
~Z()
{
--cnt;
std::cout << "Z(" << this << ")::~Z()\n";
}
private:
Z(Z const &);
Z & operator= (Z const &);
};
template<class T> void test_is_X(boost::shared_ptr<T> const & p)
{
BOOST_TEST(p->id() == 1);
@@ -244,7 +266,7 @@ int test_main(int, char * [])
test_is_nonzero(boost::make_shared(wp2));
}
weak_ptr<Y> wp3 = shared_dynamic_cast<Y>(boost::make_shared(wp2));
weak_ptr<Y> wp3 = shared_dynamic_cast<Y>(boost::make_shared(wp2));
BOOST_TEST(wp3.use_count() == 1);
BOOST_TEST(wp3.get() != 0);
@@ -302,7 +324,17 @@ int test_main(int, char * [])
BOOST_TEST(b1 == (wp1 < wp5));
BOOST_TEST(b2 == (wp5 < wp1));
shared_ptr<int> p6(get_object(), release_object);
{
// note that both get_object and release_object deal with int*
shared_ptr<void> p6(get_object(), release_object);
}
{
// test intrusive counting
boost::shared_ptr<void> pv(new Z);
boost::shared_ptr<Z> pz = boost::shared_static_cast<Z>(pv);
BOOST_TEST(pz.use_count() == pz->use_count());
}
}
BOOST_TEST(cnt == 0);