forked from boostorg/smart_ptr
Merged revision(s) 81149, 81159, 81171, 81174, 81219-81220, 81222-81224, 81226, 81229-81239, 81242, 81253, 81257-81262, 81265-81268, 81271-81272, 81275-81277, 81299-81300 from trunk:
Implement shared_ptr<X[]>, weak_ptr<X[]>. Refs #1113. ........ Fix shared_ptr<T[]> EDG issues. ........ Disable make_shared<T> overloads when T is Q[]. ........ Add catch(...) clauses to sp_array_test.cpp. ........ Add allocate_shared and make_shared for shared_ptr arrays of runtime size. Fulfills need for allocate_shared_array and make_shared_array. ........ Update Jamfile.v2 to run make_shared array tests and allocate_shared array tests. ........ Fix g++ issues. ........ Add specialization of sp_if_not_array<T[N]>. ........ Rename make_shared.hpp to make_shared_object.hpp, include from make_shared.hpp. ........ Add make_shared_array_args_test.cpp. ........ Add support for make_shared of array of arrays. Correctly destroy elements and construct elements for the variadic template constructor variants. ........ Fix sp_convertible<T const[], T const[]>. ........ Update smart_ptr/detail/array_helper to have create and create_noinit for non-array case. ........ Rename sp_convertible_test.cpp to shared_ptr_convertible_test.cpp. ........ Don't treat array_helper create and create_noinit for array types as a special case. ........ Add sp_convertible_test.cpp. ........ Fix array_helper (create_noinit and use of args...). ........ Update allocate_shared and make_shared to treat multidimensional array as single dimension. Remove detail array_helper. Add detail array traits. Update tests. ........ Simplify array_deleter interface ........ Add missing semicolon. ........ Fix typo. ........ Add tests for variadic template constructors overload of array forms of make_shared and allocate_shared for multidimensional arrays and up to 9 constructor arguments. ........ Add support for shared_ptr<X[N>. ........ Add C++11 initializer list support for make_shared and allocate_shared array forms. ........ Clean up code in allocate_shared_array.hpp and make_shared_array.hpp ........ Change make_shared and allocate_shared array form semantics with initializer lists overload that takes no size. ........ Disable make_shared for arrays when the compiler doesn't support partial specialization or SFINAE. ........ For allocate_shared and make_shared: Separate test case that g++ does support yet. Remove macros testing for no partial specialization in traits. Add additional traits. ........ Actually remove test cases from make_shared_array_create_test.cpp and allocate_shared_array_create_test.cpp that g++ does not handle. ........ Add overloads to support fixed size arrays, T[N], to allocate_shared (variadic) and make_shared (variadic) and make_shared_noinit. ........ Add additional overload for make_shared and allocate_shared for arrays for fixed size arrays and initializer lists. ........ Add assertion to overload of make_shared and allocate_shared for T[N] with initializer lists. Rename detail type to be more intuitive. ........ Add allocate_shared_array_args_test.cpp. ........ Keep old definition of sp_assert_convertible when BOOST_SP_NO_SP_CONVERTIBLE is set. ........ Updated shared_array to match shared_ptr. Refs #1113. ........ Add final overload of make_shared and allocate_shared (array forms) for T[][N] with C++11 initializer lists. ........ Change traits for initializer list for g++ ........ Tidy long line formatting in allocate_shared_array.hpp and make_shared_array.hpp ........ Update tests for make_shared and allocate_shared array forms, for normal case, initializer lists, variadic template arguments, for arrays and fixed size arrays. ........ Update Jamfile.v2 with two new smart_ptr tests for allocate_shared and make_shared ........ [SVN r81339]
This commit is contained in:
+78
-1
@@ -46,7 +46,7 @@ import testing ;
|
||||
[ run spinlock_pool_test.cpp ]
|
||||
[ run make_shared_test.cpp ]
|
||||
[ run make_shared_perfect_forwarding_test.cpp ]
|
||||
[ run sp_convertible_test.cpp ]
|
||||
[ run shared_ptr_convertible_test.cpp ]
|
||||
[ run wp_convertible_test.cpp ]
|
||||
[ run ip_convertible_test.cpp ]
|
||||
[ run allocate_shared_test.cpp ]
|
||||
@@ -70,5 +70,82 @@ import testing ;
|
||||
[ run ip_hash_test.cpp ]
|
||||
[ run owner_less_test.cpp ]
|
||||
[ run sp_unique_ptr_test.cpp ]
|
||||
[ run sp_array_test.cpp ]
|
||||
[ compile sp_array_cv_test.cpp ]
|
||||
[ run sp_convertible_test.cpp ]
|
||||
[ run sp_array_n_test.cpp ]
|
||||
|
||||
[ compile-fail array_fail_spa_sp_c.cpp ]
|
||||
[ compile-fail array_fail_sp_spa_c.cpp ]
|
||||
[ compile-fail array_fail_spa_spa_c.cpp ]
|
||||
[ compile-fail array_fail_spa_wp_c.cpp ]
|
||||
[ compile-fail array_fail_sp_wpa_c.cpp ]
|
||||
[ compile-fail array_fail_spa_wpa_c.cpp ]
|
||||
[ compile-fail array_fail_wpa_wp_c.cpp ]
|
||||
[ compile-fail array_fail_wp_wpa_c.cpp ]
|
||||
[ compile-fail array_fail_wpa_wpa_c.cpp ]
|
||||
[ compile-fail array_fail_ap_spa_c.cpp ]
|
||||
[ compile-fail array_fail_upa_sp_c.cpp ]
|
||||
[ compile-fail array_fail_up_spa_c.cpp ]
|
||||
|
||||
[ compile-fail array_fail_spa_sp_mc.cpp ]
|
||||
[ compile-fail array_fail_sp_spa_mc.cpp ]
|
||||
[ compile-fail array_fail_spa_spa_mc.cpp ]
|
||||
[ compile-fail array_fail_spa_wp_mc.cpp ]
|
||||
[ compile-fail array_fail_sp_wpa_mc.cpp ]
|
||||
[ compile-fail array_fail_spa_wpa_mc.cpp ]
|
||||
[ compile-fail array_fail_wpa_wp_mc.cpp ]
|
||||
[ compile-fail array_fail_wp_wpa_mc.cpp ]
|
||||
[ compile-fail array_fail_wpa_wpa_mc.cpp ]
|
||||
[ compile-fail array_fail_ap_spa_mc.cpp ]
|
||||
[ compile-fail array_fail_upa_sp_mc.cpp ]
|
||||
[ compile-fail array_fail_up_spa_mc.cpp ]
|
||||
|
||||
[ compile-fail array_fail_spa_sp_a.cpp ]
|
||||
[ compile-fail array_fail_sp_spa_a.cpp ]
|
||||
[ compile-fail array_fail_spa_spa_a.cpp ]
|
||||
[ compile-fail array_fail_spa_wp_a.cpp ]
|
||||
[ compile-fail array_fail_sp_wpa_a.cpp ]
|
||||
[ compile-fail array_fail_spa_wpa_a.cpp ]
|
||||
[ compile-fail array_fail_wpa_wp_a.cpp ]
|
||||
[ compile-fail array_fail_wp_wpa_a.cpp ]
|
||||
[ compile-fail array_fail_wpa_wpa_a.cpp ]
|
||||
[ compile-fail array_fail_ap_spa_a.cpp ]
|
||||
[ compile-fail array_fail_upa_sp_a.cpp ]
|
||||
[ compile-fail array_fail_up_spa_a.cpp ]
|
||||
|
||||
[ compile-fail array_fail_spa_sp_ma.cpp ]
|
||||
[ compile-fail array_fail_sp_spa_ma.cpp ]
|
||||
[ compile-fail array_fail_spa_spa_ma.cpp ]
|
||||
[ compile-fail array_fail_spa_wp_ma.cpp ]
|
||||
[ compile-fail array_fail_sp_wpa_ma.cpp ]
|
||||
[ compile-fail array_fail_spa_wpa_ma.cpp ]
|
||||
[ compile-fail array_fail_wpa_wp_ma.cpp ]
|
||||
[ compile-fail array_fail_wp_wpa_ma.cpp ]
|
||||
[ compile-fail array_fail_wpa_wpa_ma.cpp ]
|
||||
[ compile-fail array_fail_ap_spa_ma.cpp ]
|
||||
[ compile-fail array_fail_upa_sp_ma.cpp ]
|
||||
[ compile-fail array_fail_up_spa_ma.cpp ]
|
||||
|
||||
[ compile-fail array_fail_dereference.cpp ]
|
||||
[ compile-fail array_fail_member_access.cpp ]
|
||||
[ compile-fail array_fail_array_access.cpp ]
|
||||
|
||||
[ run make_shared_array_test.cpp ]
|
||||
[ run make_shared_arrays_test.cpp ]
|
||||
[ run make_shared_array_create_test.cpp ]
|
||||
[ run make_shared_array_init_test.cpp ]
|
||||
[ run make_shared_arrays_create_test.cpp ]
|
||||
[ run make_shared_array_throws_test.cpp ]
|
||||
[ run make_shared_array_esft_test.cpp ]
|
||||
[ run make_shared_array_args_test.cpp ]
|
||||
[ run allocate_shared_array_test.cpp ]
|
||||
[ run allocate_shared_arrays_test.cpp ]
|
||||
[ run allocate_shared_array_create_test.cpp ]
|
||||
[ run allocate_shared_array_init_test.cpp ]
|
||||
[ run allocate_shared_arrays_create_test.cpp ]
|
||||
[ run allocate_shared_array_throws_test.cpp ]
|
||||
[ run allocate_shared_array_esft_test.cpp ]
|
||||
[ run allocate_shared_array_args_test.cpp ]
|
||||
;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
// allocate_shared_array_args_test.cpp
|
||||
//
|
||||
// Copyright 2007-2009, 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
|
||||
class X
|
||||
{
|
||||
private:
|
||||
|
||||
X( X const & );
|
||||
X & operator=( X const & );
|
||||
|
||||
void * operator new[]( std::size_t n );
|
||||
void operator delete[]( void * p );
|
||||
|
||||
public:
|
||||
|
||||
static int instances;
|
||||
|
||||
int v;
|
||||
|
||||
explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 )
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
--instances;
|
||||
}
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 0 );
|
||||
BOOST_TEST( px[1].v == 0 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1 );
|
||||
BOOST_TEST( px[1].v == 1 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2 );
|
||||
BOOST_TEST( px[1].v == 1+2 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3 );
|
||||
BOOST_TEST( px[1].v == 1+2+3 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6, 7 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6, 7, 8 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8+9 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8+9 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static int instances;
|
||||
explicit type(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0, int g=0, int h=0, int i=0)
|
||||
: a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i) {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
const int a;
|
||||
const int b;
|
||||
const int c;
|
||||
const int d;
|
||||
const int e;
|
||||
const int f;
|
||||
const int g;
|
||||
const int h;
|
||||
const int i;
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(type::instances == 2);
|
||||
BOOST_TEST(a1[0].a == 1);
|
||||
BOOST_TEST(a1[0].d == 4);
|
||||
BOOST_TEST(a1[1].f == 6);
|
||||
BOOST_TEST(a1[1].i == 9);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2]> a1 = boost::allocate_shared<type[2]>(std::allocator<type>(), 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(type::instances == 2);
|
||||
BOOST_TEST(a1[0].a == 1);
|
||||
BOOST_TEST(a1[0].d == 4);
|
||||
BOOST_TEST(a1[1].f == 6);
|
||||
BOOST_TEST(a1[1].i == 9);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
BOOST_TEST(a1[0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1].d == 4);
|
||||
BOOST_TEST(a1[1][0].f == 6);
|
||||
BOOST_TEST(a1[1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>(), 1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
BOOST_TEST(a1[0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1].d == 4);
|
||||
BOOST_TEST(a1[1][0].f == 6);
|
||||
BOOST_TEST(a1[1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
BOOST_TEST(a1[0][0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1][0].c == 3);
|
||||
BOOST_TEST(a1[1][0][1].e == 5);
|
||||
BOOST_TEST(a1[1][1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2]> a1 = boost::allocate_shared<type[2][2][2]>(std::allocator<type>(), 1, 2, 3, 4, 5);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
BOOST_TEST(a1[0][0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1][0].c == 3);
|
||||
BOOST_TEST(a1[1][0][1].e == 5);
|
||||
BOOST_TEST(a1[1][1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2][2]> a1 = boost::allocate_shared<type[][2][2][2]>(std::allocator<type>(), 2, 1, 2, 3);
|
||||
BOOST_TEST(type::instances == 16);
|
||||
BOOST_TEST(a1[0][0][0][1].a == 1);
|
||||
BOOST_TEST(a1[0][0][1][0].c == 3);
|
||||
BOOST_TEST(a1[0][1][0][0].f == 0);
|
||||
BOOST_TEST(a1[1][0][0][0].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2][2]> a1 = boost::allocate_shared<type[2][2][2][2]>(std::allocator<type>(), 1, 2, 3);
|
||||
BOOST_TEST(type::instances == 16);
|
||||
BOOST_TEST(a1[0][0][0][1].a == 1);
|
||||
BOOST_TEST(a1[0][0][1][0].c == 3);
|
||||
BOOST_TEST(a1[0][1][0][0].f == 0);
|
||||
BOOST_TEST(a1[1][0][0][0].i == 0);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||
|
||||
class type
|
||||
: public boost::enable_shared_from_this<type> {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type() {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
type(int value)
|
||||
: value(value) {
|
||||
}
|
||||
const int value;
|
||||
private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[4]> a1 = boost::allocate_shared<const int[4]>(std::allocator<int>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<type[4]> a1 = boost::allocate_shared<type[4]>(std::allocator<type>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const type[4]> a1 = boost::allocate_shared<const type[4]>(std::allocator<type>(), { 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type(int = 0, int = 0)
|
||||
: member() {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
double member;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3, 1, 5);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>(), 1, 5);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3, 1, 5);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(std::allocator<type>(), 1, 5);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type() {
|
||||
if (instances == 5) {
|
||||
throw true;
|
||||
}
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared<type[]>(std::allocator<type>(), 6);
|
||||
BOOST_ERROR("allocate_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared<type[][2]>(std::allocator<type>(), 3);
|
||||
BOOST_ERROR("allocate_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 2);
|
||||
BOOST_TEST(a1[1][1] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 2);
|
||||
BOOST_TEST(a1[1][1] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[][2][2]> a1 = boost::allocate_shared<int[][2][2]>(std::allocator<int>(), 2, { {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0][0] == 0);
|
||||
BOOST_TEST(a1[0][0][1] == 1);
|
||||
BOOST_TEST(a1[1][1][0] == 2);
|
||||
BOOST_TEST(a1[1][1][1] == 3);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type(int = 0, int = 0)
|
||||
: member() {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
double member;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
{
|
||||
boost::shared_ptr<int[][2][2]> a1 = boost::allocate_shared<int[][2][2]>(std::allocator<int>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0][1] == 0);
|
||||
BOOST_TEST(a1[0][1][0] == 0);
|
||||
BOOST_TEST(a1[1][0][0] == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[][2][2]> a1 = boost::allocate_shared<const int[][2][2]>(std::allocator<int>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0][1] == 0);
|
||||
BOOST_TEST(a1[0][1][0] == 0);
|
||||
BOOST_TEST(a1[1][0][0] == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2][2]> a1 = boost::allocate_shared<const type[][2][2]>(std::allocator<type>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2, 1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2]> a1 = boost::allocate_shared<type[2][2][2]>(std::allocator<type>(), 1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2][2]> a1 = boost::allocate_shared<const type[][2][2]>(std::allocator<type>(), 2, 1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2][2]> a1 = boost::allocate_shared<const type[2][2][2]>(std::allocator<type>(), 1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::auto_ptr<X> px;
|
||||
boost::shared_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::auto_ptr<X> px;
|
||||
boost::shared_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2; px2 = std::auto_ptr<X>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2(( std::auto_ptr<X>() ));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px( new X );
|
||||
px[ 0 ];
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px( new X[ 1 ] );
|
||||
*px;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
int m;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px( new X[ 1 ] );
|
||||
px->m = 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px;
|
||||
boost::shared_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px;
|
||||
boost::shared_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2; px2 = boost::shared_ptr<X>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2(( boost::shared_ptr<X>() ));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px;
|
||||
boost::weak_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px;
|
||||
boost::weak_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2; px2 = boost::shared_ptr<X>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2(( boost::shared_ptr<X>() ));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px;
|
||||
boost::shared_ptr<X> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px;
|
||||
boost::shared_ptr<X> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px2; px2 = boost::shared_ptr<X[]>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px2(( boost::shared_ptr<X[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Y[]> px;
|
||||
boost::shared_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Y[]> px;
|
||||
boost::shared_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2; px2 = boost::shared_ptr<Y[]>();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2(( boost::shared_ptr<Y[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px;
|
||||
boost::weak_ptr<X> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px;
|
||||
boost::weak_ptr<X> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X> px2; px2 = boost::shared_ptr<X[]>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X> px2(( boost::shared_ptr<X[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Y[]> px;
|
||||
boost::weak_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Y[]> px;
|
||||
boost::weak_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2; px2 = boost::shared_ptr<Y[]>();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2(( boost::shared_ptr<Y[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<X> px;
|
||||
boost::shared_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<X> px;
|
||||
boost::shared_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2; px2 = std::unique_ptr<X>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X[]> px2(( std::unique_ptr<X>() ));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<X[]> px;
|
||||
boost::shared_ptr<X> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<X[]> px;
|
||||
boost::shared_ptr<X> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px2; px2 = std::unique_ptr<X[]>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<X> px2(( std::unique_ptr<X[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X> px;
|
||||
boost::weak_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X> px;
|
||||
boost::weak_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2; px2 = boost::weak_ptr<X>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2(( boost::weak_ptr<X>() ));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px;
|
||||
boost::weak_ptr<X> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px;
|
||||
boost::weak_ptr<X> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X> px2; px2 = boost::weak_ptr<X[]>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X> px2(( boost::weak_ptr<X[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<Y[]> px;
|
||||
boost::weak_ptr<X[]> px2; px2 = px;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<Y[]> px;
|
||||
boost::weak_ptr<X[]> px2( px );
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2; px2 = boost::weak_ptr<Y[]>();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::weak_ptr<X[]> px2(( boost::weak_ptr<Y[]>() ));
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
// make_shared_array_args_test.cpp
|
||||
//
|
||||
// Copyright 2007-2009, 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
class X
|
||||
{
|
||||
private:
|
||||
|
||||
X( X const & );
|
||||
X & operator=( X const & );
|
||||
|
||||
void * operator new[]( std::size_t n );
|
||||
void operator delete[]( void * p );
|
||||
|
||||
public:
|
||||
|
||||
static int instances;
|
||||
|
||||
int v;
|
||||
|
||||
explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 )
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
--instances;
|
||||
}
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 0 );
|
||||
BOOST_TEST( px[1].v == 0 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1 );
|
||||
BOOST_TEST( px[1].v == 1 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2 );
|
||||
BOOST_TEST( px[1].v == 1+2 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3 );
|
||||
BOOST_TEST( px[1].v == 1+2+3 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7, 8 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 );
|
||||
|
||||
BOOST_TEST( X::instances == 2 );
|
||||
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8+9 );
|
||||
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8+9 );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static int instances;
|
||||
explicit type(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0, int g=0, int h=0, int i=0)
|
||||
: a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i) {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
const int a;
|
||||
const int b;
|
||||
const int c;
|
||||
const int d;
|
||||
const int e;
|
||||
const int f;
|
||||
const int g;
|
||||
const int h;
|
||||
const int i;
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(2, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(type::instances == 2);
|
||||
BOOST_TEST(a1[0].a == 1);
|
||||
BOOST_TEST(a1[0].d == 4);
|
||||
BOOST_TEST(a1[1].f == 6);
|
||||
BOOST_TEST(a1[1].i == 9);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2]> a1 = boost::make_shared<type[2]>(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(type::instances == 2);
|
||||
BOOST_TEST(a1[0].a == 1);
|
||||
BOOST_TEST(a1[0].d == 4);
|
||||
BOOST_TEST(a1[1].f == 6);
|
||||
BOOST_TEST(a1[1].i == 9);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2, 1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
BOOST_TEST(a1[0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1].d == 4);
|
||||
BOOST_TEST(a1[1][0].f == 6);
|
||||
BOOST_TEST(a1[1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>(1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
BOOST_TEST(a1[0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1].d == 4);
|
||||
BOOST_TEST(a1[1][0].f == 6);
|
||||
BOOST_TEST(a1[1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2, 1, 2, 3, 4, 5);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
BOOST_TEST(a1[0][0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1][0].c == 3);
|
||||
BOOST_TEST(a1[1][0][1].e == 5);
|
||||
BOOST_TEST(a1[1][1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared<type[2][2][2]>(1, 2, 3, 4, 5);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
BOOST_TEST(a1[0][0][0].a == 1);
|
||||
BOOST_TEST(a1[0][1][0].c == 3);
|
||||
BOOST_TEST(a1[1][0][1].e == 5);
|
||||
BOOST_TEST(a1[1][1][1].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2][2]> a1 = boost::make_shared<type[][2][2][2]>(2, 1, 2, 3);
|
||||
BOOST_TEST(type::instances == 16);
|
||||
BOOST_TEST(a1[0][0][0][1].a == 1);
|
||||
BOOST_TEST(a1[0][0][1][0].c == 3);
|
||||
BOOST_TEST(a1[0][1][0][0].f == 0);
|
||||
BOOST_TEST(a1[1][0][0][0].i == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2][2]> a1 = boost::make_shared<type[2][2][2][2]>(1, 2, 3);
|
||||
BOOST_TEST(type::instances == 16);
|
||||
BOOST_TEST(a1[0][0][0][1].a == 1);
|
||||
BOOST_TEST(a1[0][0][1][0].c == 3);
|
||||
BOOST_TEST(a1[0][1][0][0].f == 0);
|
||||
BOOST_TEST(a1[1][0][0][0].i == 0);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
class type
|
||||
: public boost::enable_shared_from_this<type> {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type() {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
type(int value)
|
||||
: value(value) {
|
||||
}
|
||||
const int value;
|
||||
private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[4]> a1 = boost::make_shared<const int[4]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<type[4]> a1 = boost::make_shared<type[4]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const type[4]> a1 = boost::make_shared<const type[4]>({ 0, 1, 2, 3 });
|
||||
BOOST_TEST(a1[0].value == 0);
|
||||
BOOST_TEST(a1[1].value == 1);
|
||||
BOOST_TEST(a1[2].value == 2);
|
||||
BOOST_TEST(a1[3].value == 3);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type(int = 0, int = 0)
|
||||
: member() {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
double member;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3, 1, 5);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::make_shared<type[3]>(1, 5);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3, 1, 5);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::make_shared<const type[3]>(1, 5);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::make_shared_noinit<type[3]>();
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::make_shared_noinit<const type[]>(3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::make_shared_noinit<const type[3]>();
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type() {
|
||||
if (instances == 5) {
|
||||
throw true;
|
||||
}
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared<type[]>(6);
|
||||
BOOST_ERROR("make_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared<type[][2]>(3);
|
||||
BOOST_ERROR("make_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared_noinit<type[]>(6);
|
||||
BOOST_ERROR("make_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared_noinit<type[][2]>(3);
|
||||
BOOST_ERROR("make_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>({ {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 2);
|
||||
BOOST_TEST(a1[1][1] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 2);
|
||||
BOOST_TEST(a1[1][1] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[][2][2]> a1 = boost::make_shared<int[][2][2]>(2, { {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0][0] == 0);
|
||||
BOOST_TEST(a1[0][0][1] == 1);
|
||||
BOOST_TEST(a1[1][1][0] == 2);
|
||||
BOOST_TEST(a1[1][1][1] == 3);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
explicit type(int = 0, int = 0)
|
||||
: member() {
|
||||
instances++;
|
||||
}
|
||||
~type() {
|
||||
instances--;
|
||||
}
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
double member;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
|
||||
int main() {
|
||||
{
|
||||
boost::shared_ptr<int[][2][2]> a1 = boost::make_shared<int[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0][1] == 0);
|
||||
BOOST_TEST(a1[0][1][0] == 0);
|
||||
BOOST_TEST(a1[1][0][0] == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[][2][2]> a1 = boost::make_shared<const int[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0][1] == 0);
|
||||
BOOST_TEST(a1[0][1][0] == 0);
|
||||
BOOST_TEST(a1[1][0][0] == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared<const type[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2, 1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared<type[2][2][2]>(1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared<const type[][2][2]>(2, 1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2][2]> a1 = boost::make_shared<const type[2][2][2]>(1, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
boost::shared_ptr<int[][2][2]> a1 = boost::make_shared_noinit<int[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[2][2][2]> a1 = boost::make_shared_noinit<int[2][2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[][2][2]> a1 = boost::make_shared_noinit<const int[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[2][2][2]> a1 = boost::make_shared_noinit<const int[2][2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared_noinit<type[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared_noinit<type[2][2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared_noinit<const type[][2][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2][2]> a1 = boost::make_shared_noinit<const type[2][2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
// sp_convertible_test.cpp
|
||||
//
|
||||
// Copyright (c) 2008 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
//
|
||||
|
||||
class incomplete;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
};
|
||||
|
||||
struct Z: public X
|
||||
{
|
||||
};
|
||||
|
||||
int f( boost::shared_ptr<void const> )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f( boost::shared_ptr<int> )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int f( boost::shared_ptr<incomplete> )
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
int g( boost::shared_ptr<X> )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
int g( boost::shared_ptr<Y> )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
int g( boost::shared_ptr<incomplete> )
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<double> p1;
|
||||
BOOST_TEST( 1 == f( p1 ) );
|
||||
BOOST_TEST( 1 == f( boost::shared_ptr<double>() ) );
|
||||
|
||||
boost::shared_ptr<Z> p2;
|
||||
BOOST_TEST( 4 == g( p2 ) );
|
||||
BOOST_TEST( 4 == g( boost::shared_ptr<Z>() ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -236,7 +236,7 @@ void test()
|
||||
ca2.reset();
|
||||
BOOST_TEST( ca.use_count() == 2 );
|
||||
BOOST_TEST( ca3.use_count() == 2 );
|
||||
BOOST_TEST( ca2.use_count() == 1 );
|
||||
BOOST_TEST( ca2.use_count() == 0 );
|
||||
|
||||
ca.reset();
|
||||
BOOST_TEST( ca.get() == 0 );
|
||||
@@ -269,7 +269,7 @@ void test()
|
||||
udta2.reset();
|
||||
BOOST_TEST( udta2.get() == 0 );
|
||||
BOOST_TEST( udta.use_count() == 1 );
|
||||
BOOST_TEST( udta2.use_count() == 1 );
|
||||
BOOST_TEST( udta2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( UDT_use_count == 4 ); // reality check
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// sp_array_cv_test.cpp
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
class B
|
||||
{
|
||||
};
|
||||
|
||||
class D: public B
|
||||
{
|
||||
};
|
||||
|
||||
#define TEST_CONV( T, U ) \
|
||||
{ \
|
||||
boost::shared_ptr< T > p1; \
|
||||
boost::shared_ptr< U > p2( p1 ); \
|
||||
p2 = p1; \
|
||||
boost::shared_ptr< U > p3 = boost::shared_ptr< T >(); \
|
||||
p3 = boost::shared_ptr< T >(); \
|
||||
}
|
||||
|
||||
#define TEST_CV_TRUE( T, U ) \
|
||||
TEST_CONV( T, U ) \
|
||||
TEST_CONV( T, const U ) \
|
||||
TEST_CONV( T, volatile U ) \
|
||||
TEST_CONV( T, const volatile U ) \
|
||||
TEST_CONV( const T, const U ) \
|
||||
TEST_CONV( const T, const volatile U ) \
|
||||
TEST_CONV( volatile T, volatile U ) \
|
||||
TEST_CONV( volatile T, const volatile U ) \
|
||||
TEST_CONV( const volatile T, const volatile U )
|
||||
|
||||
int main()
|
||||
{
|
||||
TEST_CV_TRUE( X, X )
|
||||
TEST_CV_TRUE( X, void )
|
||||
TEST_CV_TRUE( D, B )
|
||||
|
||||
TEST_CV_TRUE( X[], X[] )
|
||||
TEST_CV_TRUE( X[3], X[3] )
|
||||
|
||||
TEST_CV_TRUE( X[3], X[] )
|
||||
|
||||
TEST_CV_TRUE( X[], void )
|
||||
TEST_CV_TRUE( X[3], void )
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
//
|
||||
// sp_array_n_test.cpp
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
class X: public boost::enable_shared_from_this< X >
|
||||
{
|
||||
public:
|
||||
|
||||
static int allocations;
|
||||
static int instances;
|
||||
|
||||
X()
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
--instances;
|
||||
}
|
||||
|
||||
void* operator new[]( std::size_t n )
|
||||
{
|
||||
++allocations;
|
||||
return ::operator new[]( n );
|
||||
}
|
||||
|
||||
void operator delete[]( void* p )
|
||||
{
|
||||
--allocations;
|
||||
::operator delete[]( p );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
X( X const& );
|
||||
X& operator=( X const& );
|
||||
};
|
||||
|
||||
int X::allocations = 0;
|
||||
int X::instances = 0;
|
||||
|
||||
template< class T> class array_deleter
|
||||
{
|
||||
public:
|
||||
|
||||
static int calls;
|
||||
|
||||
void operator()( T * p ) const
|
||||
{
|
||||
++calls;
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template< class Y > void operator()( Y * p ) const;
|
||||
};
|
||||
|
||||
template< class T > int array_deleter< T >::calls = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
boost::shared_ptr<X[3]> px;
|
||||
BOOST_TEST( !px );
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
boost::shared_ptr<X[3]> px2( new X[ 3 ] );
|
||||
BOOST_TEST( px2 );
|
||||
|
||||
try
|
||||
{
|
||||
px2[0].shared_from_this();
|
||||
BOOST_ERROR( "px2[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 3 );
|
||||
|
||||
{
|
||||
X & rx = px2[ 0 ];
|
||||
BOOST_TEST( &rx == px2.get() );
|
||||
}
|
||||
|
||||
boost::shared_ptr<X const[3]> px3( px2 );
|
||||
BOOST_TEST( px3 == px2 );
|
||||
BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) );
|
||||
|
||||
{
|
||||
X const & rx = px3[ 1 ];
|
||||
BOOST_TEST( &rx == px3.get() + 1 );
|
||||
}
|
||||
|
||||
px3.reset();
|
||||
px3 = px2;
|
||||
BOOST_TEST( px3 == px2 );
|
||||
BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) );
|
||||
|
||||
boost::shared_ptr<X volatile[3]> px4( px2 );
|
||||
BOOST_TEST( px4 == px2 );
|
||||
BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) );
|
||||
|
||||
{
|
||||
X volatile & rx = px4[ 2 ];
|
||||
BOOST_TEST( &rx == px4.get() + 2 );
|
||||
}
|
||||
|
||||
px4.reset();
|
||||
px4 = px2;
|
||||
BOOST_TEST( px4 == px2 );
|
||||
BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) );
|
||||
|
||||
boost::shared_ptr<void> px5( px2 );
|
||||
BOOST_TEST( px5 == px2 );
|
||||
BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) );
|
||||
|
||||
px5.reset();
|
||||
px5 = px2;
|
||||
BOOST_TEST( px5 == px2 );
|
||||
BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) );
|
||||
|
||||
boost::weak_ptr<X[3]> wp( px );
|
||||
BOOST_TEST( wp.lock() == px );
|
||||
|
||||
boost::weak_ptr<X[3]> wp2( px2 );
|
||||
BOOST_TEST( wp2.lock() == px2 );
|
||||
|
||||
wp2.reset();
|
||||
wp2 = px2;
|
||||
BOOST_TEST( wp2.lock() == px2 );
|
||||
|
||||
boost::weak_ptr<X const[3]> wp3( px2 );
|
||||
BOOST_TEST( wp3.lock() == px2 );
|
||||
|
||||
wp3.reset();
|
||||
wp3 = px2;
|
||||
BOOST_TEST( wp3.lock() == px2 );
|
||||
|
||||
boost::weak_ptr<X volatile[3]> wp4( px2 );
|
||||
BOOST_TEST( wp4.lock() == px2 );
|
||||
|
||||
wp4.reset();
|
||||
wp4 = px2;
|
||||
BOOST_TEST( wp4.lock() == px2 );
|
||||
|
||||
boost::weak_ptr<void> wp5( px2 );
|
||||
BOOST_TEST( wp5.lock() == px2 );
|
||||
|
||||
wp5.reset();
|
||||
wp5 = px2;
|
||||
BOOST_TEST( wp5.lock() == px2 );
|
||||
|
||||
px2.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 3 );
|
||||
|
||||
px3.reset();
|
||||
px4.reset();
|
||||
px5.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
BOOST_TEST( wp2.lock() == 0 );
|
||||
BOOST_TEST( wp3.lock() == 0 );
|
||||
BOOST_TEST( wp4.lock() == 0 );
|
||||
BOOST_TEST( wp5.lock() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<X[5]> px( new X[ 5 ], array_deleter< X >() );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 5 );
|
||||
|
||||
try
|
||||
{
|
||||
px[0].shared_from_this();
|
||||
BOOST_ERROR( "px[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
BOOST_TEST( array_deleter< X >::calls == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<X[6]> px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 6 );
|
||||
|
||||
try
|
||||
{
|
||||
px[0].shared_from_this();
|
||||
BOOST_ERROR( "px[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
BOOST_TEST( array_deleter< X >::calls == 2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
//
|
||||
// sp_array_test.cpp
|
||||
//
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
class X: public boost::enable_shared_from_this< X >
|
||||
{
|
||||
public:
|
||||
|
||||
static int allocations;
|
||||
static int instances;
|
||||
|
||||
X()
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
--instances;
|
||||
}
|
||||
|
||||
void* operator new[]( std::size_t n )
|
||||
{
|
||||
++allocations;
|
||||
return ::operator new[]( n );
|
||||
}
|
||||
|
||||
void operator delete[]( void* p )
|
||||
{
|
||||
--allocations;
|
||||
::operator delete[]( p );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
X( X const& );
|
||||
X& operator=( X const& );
|
||||
};
|
||||
|
||||
int X::allocations = 0;
|
||||
int X::instances = 0;
|
||||
|
||||
template< class T> class array_deleter
|
||||
{
|
||||
public:
|
||||
|
||||
static int calls;
|
||||
|
||||
void operator()( T * p ) const
|
||||
{
|
||||
++calls;
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template< class Y > void operator()( Y * p ) const;
|
||||
};
|
||||
|
||||
template< class T > int array_deleter< T >::calls = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
boost::shared_ptr<X[]> px;
|
||||
BOOST_TEST( !px );
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
boost::shared_ptr<X[]> px2( new X[ 3 ] );
|
||||
BOOST_TEST( px2 );
|
||||
|
||||
try
|
||||
{
|
||||
px2[0].shared_from_this();
|
||||
BOOST_ERROR( "px2[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 3 );
|
||||
|
||||
{
|
||||
X & rx = px2[ 0 ];
|
||||
BOOST_TEST( &rx == px2.get() );
|
||||
}
|
||||
|
||||
boost::shared_ptr<X const[]> px3( px2 );
|
||||
BOOST_TEST( px3 == px2 );
|
||||
BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) );
|
||||
|
||||
{
|
||||
X const & rx = px3[ 1 ];
|
||||
BOOST_TEST( &rx == px3.get() + 1 );
|
||||
}
|
||||
|
||||
px3.reset();
|
||||
px3 = px2;
|
||||
BOOST_TEST( px3 == px2 );
|
||||
BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) );
|
||||
|
||||
boost::shared_ptr<X volatile[]> px4( px2 );
|
||||
BOOST_TEST( px4 == px2 );
|
||||
BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) );
|
||||
|
||||
{
|
||||
X volatile & rx = px4[ 2 ];
|
||||
BOOST_TEST( &rx == px4.get() + 2 );
|
||||
}
|
||||
|
||||
px4.reset();
|
||||
px4 = px2;
|
||||
BOOST_TEST( px4 == px2 );
|
||||
BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) );
|
||||
|
||||
boost::shared_ptr<void> px5( px2 );
|
||||
BOOST_TEST( px5 == px2 );
|
||||
BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) );
|
||||
|
||||
px5.reset();
|
||||
px5 = px2;
|
||||
BOOST_TEST( px5 == px2 );
|
||||
BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) );
|
||||
|
||||
boost::weak_ptr<X[]> wp( px );
|
||||
BOOST_TEST( wp.lock() == px );
|
||||
|
||||
boost::weak_ptr<X[]> wp2( px2 );
|
||||
BOOST_TEST( wp2.lock() == px2 );
|
||||
|
||||
wp2.reset();
|
||||
wp2 = px2;
|
||||
BOOST_TEST( wp2.lock() == px2 );
|
||||
|
||||
boost::weak_ptr<X const[]> wp3( px2 );
|
||||
BOOST_TEST( wp3.lock() == px2 );
|
||||
|
||||
wp3.reset();
|
||||
wp3 = px2;
|
||||
BOOST_TEST( wp3.lock() == px2 );
|
||||
|
||||
boost::weak_ptr<X volatile[]> wp4( px2 );
|
||||
BOOST_TEST( wp4.lock() == px2 );
|
||||
|
||||
wp4.reset();
|
||||
wp4 = px2;
|
||||
BOOST_TEST( wp4.lock() == px2 );
|
||||
|
||||
boost::weak_ptr<void> wp5( px2 );
|
||||
BOOST_TEST( wp5.lock() == px2 );
|
||||
|
||||
wp5.reset();
|
||||
wp5 = px2;
|
||||
BOOST_TEST( wp5.lock() == px2 );
|
||||
|
||||
px2.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 3 );
|
||||
|
||||
px3.reset();
|
||||
px4.reset();
|
||||
px5.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
BOOST_TEST( wp2.lock() == 0 );
|
||||
BOOST_TEST( wp3.lock() == 0 );
|
||||
BOOST_TEST( wp4.lock() == 0 );
|
||||
BOOST_TEST( wp5.lock() == 0 );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_SMART_PTR )
|
||||
|
||||
{
|
||||
std::unique_ptr<X[]> px( new X[ 4 ] );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 4 );
|
||||
|
||||
boost::shared_ptr<X[]> px2( std::move( px ) );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 4 );
|
||||
BOOST_TEST( px.get() == 0 );
|
||||
|
||||
try
|
||||
{
|
||||
px2[0].shared_from_this();
|
||||
BOOST_ERROR( "px2[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
px2.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<X[]> px( new X[ 4 ] );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 4 );
|
||||
|
||||
boost::shared_ptr<X[]> px2;
|
||||
px2 = std::move( px );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 4 );
|
||||
BOOST_TEST( px.get() == 0 );
|
||||
|
||||
try
|
||||
{
|
||||
px2[0].shared_from_this();
|
||||
BOOST_ERROR( "px2[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px2[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
px2.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
boost::shared_ptr<X[]> px( new X[ 5 ], array_deleter< X >() );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 5 );
|
||||
|
||||
try
|
||||
{
|
||||
px[0].shared_from_this();
|
||||
BOOST_ERROR( "px[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
BOOST_TEST( array_deleter< X >::calls == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<X[]> px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() );
|
||||
BOOST_TEST( X::allocations == 1 );
|
||||
BOOST_TEST( X::instances == 6 );
|
||||
|
||||
try
|
||||
{
|
||||
px[0].shared_from_this();
|
||||
BOOST_ERROR( "px[0].shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_ERROR( "px[0].shared_from_this() threw something else than bad_weak_ptr" );
|
||||
}
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( X::allocations == 0 );
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
BOOST_TEST( array_deleter< X >::calls == 2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -2,70 +2,92 @@
|
||||
|
||||
// sp_convertible_test.cpp
|
||||
//
|
||||
// Copyright (c) 2008 Peter Dimov
|
||||
// Copyright (c) 2012 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
||||
|
||||
//
|
||||
|
||||
class incomplete;
|
||||
class X;
|
||||
|
||||
struct X
|
||||
class B
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
class D: public B
|
||||
{
|
||||
};
|
||||
|
||||
struct Z: public X
|
||||
{
|
||||
};
|
||||
#define TEST_CV_TRUE( T, U ) \
|
||||
BOOST_TEST(( sp_convertible< T, U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< T, const U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< T, volatile U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< T, const volatile U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< const T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const T, const U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< const T, volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const T, const volatile U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, const U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, volatile U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, const volatile U >::value == true )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, const U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, const volatile U >::value == true ));
|
||||
|
||||
int f( boost::shared_ptr<void const> )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f( boost::shared_ptr<int> )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int f( boost::shared_ptr<incomplete> )
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
int g( boost::shared_ptr<X> )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
int g( boost::shared_ptr<Y> )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
int g( boost::shared_ptr<incomplete> )
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
#define TEST_CV_FALSE( T, U ) \
|
||||
BOOST_TEST(( sp_convertible< T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< T, const U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< T, volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< T, const volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const T, const U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const T, volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const T, const volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, const U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< volatile T, const volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, const U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, volatile U >::value == false )); \
|
||||
BOOST_TEST(( sp_convertible< const volatile T, const volatile U >::value == false ));
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<double> p1;
|
||||
BOOST_TEST( 1 == f( p1 ) );
|
||||
BOOST_TEST( 1 == f( boost::shared_ptr<double>() ) );
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
|
||||
|
||||
boost::shared_ptr<Z> p2;
|
||||
BOOST_TEST( 4 == g( p2 ) );
|
||||
BOOST_TEST( 4 == g( boost::shared_ptr<Z>() ) );
|
||||
using boost::detail::sp_convertible;
|
||||
|
||||
TEST_CV_TRUE( X, X )
|
||||
TEST_CV_TRUE( X, void )
|
||||
TEST_CV_FALSE( void, X )
|
||||
TEST_CV_TRUE( D, B )
|
||||
TEST_CV_FALSE( B, D )
|
||||
|
||||
TEST_CV_TRUE( X[], X[] )
|
||||
TEST_CV_FALSE( D[], B[] )
|
||||
|
||||
TEST_CV_TRUE( X[3], X[3] )
|
||||
TEST_CV_FALSE( X[3], X[4] )
|
||||
TEST_CV_FALSE( D[3], B[3] )
|
||||
|
||||
TEST_CV_TRUE( X[3], X[] )
|
||||
TEST_CV_FALSE( X[], X[3] )
|
||||
|
||||
TEST_CV_TRUE( X[], void )
|
||||
TEST_CV_FALSE( void, X[] )
|
||||
|
||||
TEST_CV_TRUE( X[3], void )
|
||||
TEST_CV_FALSE( void, X[3] )
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user