http://stxxl.sourceforge.net
<tb@panthema.net>
http://www.boost.org/LICENSE_1_0.txt
#include <stxxl/bits/common/counting_ptr.h>
#include <stxxl/bits/verbose.h>
static unsigned int count_deletes = 0;
struct my_int : public stxxl::counted_object
{
int i;
my_int(int _i) : i(_i) { }
~my_int()
{ ++count_deletes; }
};
typedef stxxl::counting_ptr<my_int> int_ptr;
typedef stxxl::const_counting_ptr<my_int> int_cptr;
int_cptr run_test()
{
int_ptr i1 = new my_int(42);
STXXL_CHECK(i1->i == 42);
STXXL_CHECK((*i1).i == 42);
STXXL_CHECK(i1.get()->i == 42);
STXXL_CHECK(i1->unique());
int_ptr i2 = i1;
STXXL_CHECK(i2->i == 42);
STXXL_CHECK(!i1->unique());
STXXL_CHECK(i1 == i2);
STXXL_CHECK(i1->get_reference_count() == 2);
int_ptr i3 = i2;
STXXL_CHECK(i3->i == 42);
STXXL_CHECK(i3->get_reference_count() == 3);
i3 = new my_int(5);
STXXL_CHECK(i1 != i3);
STXXL_CHECK(i1->get_reference_count() == 2);
int_cptr i4 = i3;
return i4;
}
int main()
{
{
int_cptr t1 = run_test();
STXXL_CHECK(count_deletes == 1);
}
STXXL_CHECK(count_deletes == 2);
return 0;
}