#include <boost/smart_ptr/intrusive_ref_counter.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <cstddef>
namespace N1 {
class my_class :
public boost::intrusive_ref_counter< my_class >
{
public:
static unsigned int destructor_count;
~my_class()
{
++destructor_count;
}
};
unsigned int my_class::destructor_count = 0;
}
namespace N2 {
class my_class :
public boost::intrusive_ref_counter< my_class, boost::thread_unsafe_counter >
{
public:
static unsigned int destructor_count;
~my_class()
{
++destructor_count;
}
};
unsigned int my_class::destructor_count = 0;
}
namespace N3 {
struct root :
public boost::intrusive_ref_counter< root >
{
virtual ~root() {}
};
}
namespace N4 {
struct X :
public virtual N3::root
{
};
}
namespace N5 {
struct Y :
public virtual N3::root
{
};
}
namespace N6 {
struct Z :
public N4::X,
public N5::Y
{
static unsigned int destructor_count;
~Z()
{
++destructor_count;
}
};
unsigned int Z::destructor_count = 0;
}
int main()
{
{
boost::intrusive_ptr< N1::my_class > p = new N1::my_class();
p = NULL;
BOOST_TEST(N1::my_class::destructor_count == 1);
}
{
boost::intrusive_ptr< N2::my_class > p = new N2::my_class();
p = NULL;
BOOST_TEST(N2::my_class::destructor_count == 1);
}
{
N1::my_class* p = new N1::my_class();
intrusive_ptr_add_ref(p);
intrusive_ptr_release(p);
BOOST_TEST(N1::my_class::destructor_count == 2);
}
{
boost::intrusive_ptr< N6::Z > p1 = new N6::Z();
BOOST_TEST(p1->use_count() == 1);
BOOST_TEST(N6::Z::destructor_count == 0);
boost::intrusive_ptr< N3::root > p2 = p1;
BOOST_TEST(p1->use_count() == 2);
BOOST_TEST(N6::Z::destructor_count == 0);
p1 = NULL;
BOOST_TEST(N6::Z::destructor_count == 0);
p2 = NULL;
BOOST_TEST(N6::Z::destructor_count == 1);
}
return boost::report_errors();
}