early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,15 @@
# Copyright 2018, 2019 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(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(HAVE_BOOST_TEST)
# for lw_thread_test.cpp
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::smart_ptr Boost::core Boost::align Boost::atomic Boost::container_hash Boost::bind Threads::Threads)
endif()

View File

@@ -0,0 +1,414 @@
# Boost.SmartPtr Library test Jamfile
#
# Copyright (c) 2003-2018 Peter Dimov
# Copyright (c) 2003 Dave Abrahams
#
# 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)
import testing ;
project
: requirements
<toolset>gcc:<cxxflags>-Wno-non-virtual-dtor
<toolset>gcc:<cxxflags>-Wno-deprecated-declarations
#<toolset>gcc:<cxxflags>-Wno-delete-non-virtual-dtor (not in 4.4/4.6)
;
# quick test (for CI)
run quick.cpp ;
# full test suite
run smart_ptr_test.cpp ;
run shared_ptr_basic_test.cpp ;
run shared_ptr_test.cpp ;
run weak_ptr_test.cpp ;
run weak_ptr_move_test.cpp ;
run shared_from_this_test.cpp ;
run get_deleter_test.cpp ;
run intrusive_ptr_test.cpp ;
run intrusive_ptr_move_test.cpp ;
run intrusive_ref_counter_test.cpp ;
run atomic_count_test.cpp ;
run lw_mutex_test.cpp ;
run lw_mutex_test.cpp : : : <define>BOOST_USE_WINDOWS_H : lw_mutex_test.win_h ;
compile-fail shared_ptr_assign_fail.cpp ;
compile-fail shared_ptr_delete_fail.cpp ;
compile-fail shared_ptr_compare_fail.cpp ;
run shared_ptr_alloc2_test.cpp ;
run pointer_cast_test.cpp ;
run cpp11_pointer_cast_test.cpp ;
compile pointer_to_other_test.cpp ;
run auto_ptr_rv_test.cpp ;
run shared_ptr_alias_test.cpp ;
run shared_ptr_rv_test.cpp ;
run shared_ptr_rv_pointer_cast_test.cpp ;
run shared_ptr_move_test.cpp ;
run shared_ptr_alias_move_test.cpp ;
run shared_ptr_reinterpret_pointer_cast_test.cpp ;
compile-fail shared_ptr_pv_fail.cpp ;
run sp_unary_addr_test.cpp ;
compile-fail scoped_ptr_eq_fail.cpp ;
compile-fail scoped_array_eq_fail.cpp ;
run esft_regtest.cpp ;
run yield_k_test.cpp ;
run yield_k_test.cpp : : : <threading>multi : yield_k_test.mt ;
run spinlock_test.cpp ;
run spinlock_try_test.cpp ;
run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ;
run spinlock_pool_test.cpp
: : :
# msvc-8.0, 9.0 optimizer codegen bug for `x % 41`
<toolset>msvc-8.0,<variant>release:<build>no
<toolset>msvc-9.0,<variant>release:<build>no ;
run make_shared_test.cpp ;
run make_shared_move_emulation_test.cpp ;
run make_shared_perfect_forwarding_test.cpp ;
run shared_ptr_convertible_test.cpp ;
run wp_convertible_test.cpp ;
run ip_convertible_test.cpp ;
run allocate_shared_test.cpp ;
run sp_atomic_test.cpp ;
run esft_void_test.cpp ;
run esft_second_ptr_test.cpp ;
run make_shared_esft_test.cpp ;
run allocate_shared_esft_test.cpp ;
run sp_recursive_assign_test.cpp ;
run sp_recursive_assign2_test.cpp ;
run sp_recursive_assign_rv_test.cpp ;
run sp_recursive_assign2_rv_test.cpp ;
compile-fail auto_ptr_lv_fail.cpp
: <toolset>gcc-4.4.7:<build>no <toolset>gcc-4.4:<build>no ;
run atomic_count_test2.cpp ;
run sp_typeinfo_test.cpp ;
compile make_shared_fp_test.cpp ;
run sp_hash_test.cpp ;
run get_deleter_array_test.cpp ;
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 ;
run sp_array_cast_test.cpp ;
run sp_zero_compare_test.cpp ;
run sp_nullptr_test.cpp ;
run sa_nullptr_test.cpp ;
run shared_ptr_alloc3_test.cpp ;
run shared_ptr_alloc11_test.cpp ;
run shared_ptr_alloc_construct11_test.cpp ;
run allocate_shared_alloc11_test.cpp ;
run allocate_shared_construct11_test.cpp ;
run sp_interlocked_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
: : : <toolset>msvc-8.0:<build>no ;
run make_shared_arrays_test.cpp ;
run make_shared_array_throws_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run make_shared_array_esft_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run make_shared_array_noinit_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run make_shared_array_value_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run allocate_shared_array_test.cpp ;
run allocate_shared_arrays_test.cpp ;
run allocate_shared_array_throws_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run allocate_shared_array_esft_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run allocate_shared_array_noinit_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run allocate_shared_array_value_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run allocate_shared_array_construct_test.cpp ;
run make_unique_test.cpp ;
run make_unique_args_test.cpp ;
run make_unique_value_test.cpp
: : : <toolset>gcc-4.6:<cxxflags>-fno-deduce-init-list ;
run make_unique_noinit_test.cpp ;
run make_unique_throws_test.cpp ;
run make_unique_array_test.cpp ;
run make_unique_array_noinit_test.cpp ;
run make_unique_array_throws_test.cpp ;
run shared_from_raw_test.cpp ;
run shared_from_raw_test2.cpp ;
run shared_from_raw_test3.cpp ;
run shared_from_raw_test4.cpp ;
run shared_from_raw_test5.cpp ;
run shared_from_raw_test6.cpp ;
run weak_from_raw_test.cpp ;
run weak_from_raw_test2.cpp ;
run weak_from_raw_test3.cpp ;
run weak_from_raw_test4.cpp ;
run weak_from_raw_test5.cpp ;
compile sp_explicit_inst_test.cpp ;
run weak_from_this_test.cpp ;
run weak_from_this_test2.cpp ;
run sp_bml_unique_ptr_test.cpp ;
run sp_hash_test2.cpp ;
run sp_hash_test3.cpp ;
run pointer_cast_test2.cpp ;
compile-fail pointer_cast_st_fail.cpp ;
compile-fail pointer_cast_st_fail2.cpp ;
compile-fail pointer_cast_st_fail3.cpp ;
compile-fail pointer_cast_co_fail.cpp ;
compile-fail pointer_cast_co_fail2.cpp ;
compile-fail pointer_cast_co_fail3.cpp ;
compile-fail pointer_cast_dy_fail.cpp ;
compile-fail pointer_cast_dy_fail2.cpp ;
compile-fail pointer_cast_dy_fail3.cpp ;
run sp_nothrow_test.cpp ;
compile make_shared_msvc_test.cpp ;
compile lwm_win32_cs_test.cpp ;
run atomic_sp_test.cpp ;
run sp_constexpr_test.cpp ;
run sp_constexpr_test2.cpp ;
run atomic_sp_constexpr_test.cpp ;
run shared_ptr_fn_test.cpp ;
run get_deleter_test2.cpp ;
run get_deleter_test3.cpp ;
run get_deleter_array_test2.cpp ;
run get_deleter_array_test3.cpp
: : : <toolset>msvc-8.0:<build>no ;
run sp_convertible_test2.cpp ;
run local_sp_test.cpp ;
run lsp_array_test.cpp ;
run lsp_array_n_test.cpp ;
run lsp_array_cv_test.cpp ;
run lsp_array_cast_test.cpp ;
run get_local_deleter_test.cpp ;
run get_local_deleter_test2.cpp ;
run get_local_deleter_test3.cpp ;
run get_local_deleter_array_test.cpp ;
run get_local_deleter_array_test2.cpp ;
run make_local_shared_test.cpp ;
run make_local_shared_esft_test.cpp ;
run allocate_local_shared_test.cpp ;
run allocate_local_shared_esft_test.cpp ;
run make_local_shared_array_test.cpp ;
run make_local_shared_arrays_test.cpp
: : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ;
run make_local_shared_array_throws_test.cpp ;
run make_local_shared_array_esft_test.cpp ;
run make_local_shared_array_noinit_test.cpp ;
run make_local_shared_array_value_test.cpp ;
run allocate_local_shared_array_test.cpp ;
run allocate_local_shared_arrays_test.cpp
: : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ;
run allocate_local_shared_array_throws_test.cpp ;
run allocate_local_shared_array_esft_test.cpp ;
run allocate_local_shared_array_noinit_test.cpp ;
run allocate_local_shared_array_value_test.cpp ;
run allocate_local_shared_array_construct_test.cpp ;
run local_sp_fn_test.cpp ;
run lsp_convertible_test.cpp ;
run lsp_convertible_test2.cpp ;
run make_shared_array_tmp_test.cpp
: : : <toolset>msvc-8.0:<build>no ;
run lw_thread_test.cpp
: : : <threading>multi ;
compile sp_windows_h_test.cpp ;
compile spinlock_windows_h_test.cpp ;
compile yield_k_windows_h_test.cpp ;
lib dll_test : dll_test_lib.cpp : <link>shared:<define>DLL_TEST_DYN_LINK=1 ;
explicit dll_test ;
run dll_test_main.cpp dll_test : : : <link>static : dll_test_static ;
run dll_test_main.cpp dll_test : : : <link>shared : dll_test_shared ;
run make_shared_const_test.cpp ;
run make_local_shared_const_test.cpp ;
lib abi_test_mt : abi_test_lib.cpp : <link>static ;
explicit abi_test_mt ;
obj abi_test_lib_nt : abi_test_lib.cpp : <define>BOOST_DISABLE_THREADS ;
explicit abi_test_lib_nt ;
lib abi_test_nt : abi_test_lib_nt : <link>static ;
explicit abi_test_nt ;
run abi_test_main.cpp abi_test_mt : : : <define>BOOST_DISABLE_THREADS : abi_test_nt_mt ;
run abi_test_main.cpp abi_test_nt : : : : abi_test_mt_nt ;
run abi_test_main.cpp abi_test_mt/<cxxstd>0x : : : <cxxstd>98 : abi_test_03_11 ;
run abi_test_main.cpp abi_test_mt/<cxxstd>98 : : : <cxxstd>0x : abi_test_11_03 ;
run weak_ptr_alias_test.cpp ;
run weak_ptr_alias_move_test.cpp ;
run sp_typeinfo_test.cpp : : : <rtti>off : sp_typeinfo_test_no_rtti ;
run get_deleter_test.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no <toolset>gcc-4.4,<cxxstd>0x:<build>no : get_deleter_test_no_rtti ;
run get_deleter_test2.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no <toolset>gcc-4.4,<cxxstd>0x:<build>no : get_deleter_test2_no_rtti ;
run get_deleter_test3.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no <toolset>gcc-4.4,<cxxstd>0x:<build>no : get_deleter_test3_no_rtti ;
run shared_from_test.cpp ;
run weak_from_test.cpp ;
run weak_from_test2.cpp ;
run allocate_unique_aggregate_test.cpp ;
run allocate_unique_args_test.cpp ;
run allocate_unique_array_construct_test.cpp ;
run allocate_unique_array_noinit_test.cpp ;
run allocate_unique_arrays_test.cpp ;
run allocate_unique_array_test.cpp ;
run allocate_unique_array_throws_test.cpp ;
run allocate_unique_array_value_test.cpp ;
run allocate_unique_construct_test.cpp ;
run allocate_unique_noinit_test.cpp ;
run allocate_unique_test.cpp ;
run allocate_unique_throws_test.cpp ;
run allocate_unique_value_test.cpp ;
run get_allocator_pointer_test.cpp ;
run sp_guides_test.cpp ;
run sp_guides_test2.cpp ;
run wp_guides_test.cpp ;
compile-fail shared_from_fail.cpp ;
compile-fail weak_from_fail.cpp ;
compile sp_override_test.cpp ;
compile sp_pedantic_test.cpp
: <warnings>pedantic
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on ;
run sp_owner_before_test.cpp ;
run sp_owner_equals_test.cpp ;
run lsp_owner_before_test.cpp ;
run lsp_owner_equals_test.cpp ;
run owner_equal_to_test.cpp ;
run owner_equal_to_test2.cpp ;
run owner_less_test2.cpp ;
run ip_hash_test2.cpp ;
run sp_hash_test4.cpp ;
run lsp_hash_test.cpp ;
run lsp_hash_test2.cpp ;
run atomic_count_mt_test.cpp
: : : <threading>multi ;
run spinlock_mt_test.cpp
: : : <threading>multi ;
run spinlock_pool_mt_test.cpp
: : : <threading>multi ;
run shared_ptr_mt_test.cpp
: : : <threading>multi ;
run weak_ptr_mt_test.cpp
: : : <threading>multi ;
compile sp_report_implementation.cpp ;
run sp_owner_hash_value_test.cpp ;
run wp_hash_test.cpp ;
run wp_hash_test2.cpp ;
run wp_unordered_test.cpp ;
run owner_hash_test.cpp ;
run sp_unordered_test.cpp ;
run sp_unique_ptr_test2.cpp ;
run sp_move_only_deleter.cpp ;

View File

@@ -0,0 +1,43 @@
// Copyright 2018 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/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_DISABLE_THREADS)
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is defined" )
#else
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is not defined" )
#endif
#if defined(BOOST_NO_CXX11_HDR_ATOMIC)
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is defined" )
#else
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is not defined" )
#endif
void abi_test_1( boost::shared_ptr<void> & p )
{
BOOST_TEST_EQ( p.use_count(), 1 );
p.reset();
BOOST_TEST_EQ( p.use_count(), 0 );
}
boost::shared_ptr<void> abi_test_2( boost::shared_ptr<void> const & p )
{
BOOST_TEST_EQ( p.use_count(), 1 );
return p;
}
boost::shared_ptr<void> abi_test_3()
{
return boost::shared_ptr<void>( static_cast<int*>( 0 ) );
}

View File

@@ -0,0 +1,82 @@
// Copyright 2018 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/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_DISABLE_THREADS)
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is defined" )
#else
BOOST_PRAGMA_MESSAGE( "BOOST_DISABLE_THREADS is not defined" )
#endif
#if defined(BOOST_NO_CXX11_HDR_ATOMIC)
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is defined" )
#else
BOOST_PRAGMA_MESSAGE( "BOOST_NO_CXX11_HDR_ATOMIC is not defined" )
#endif
void abi_test_1( boost::shared_ptr<void> & p );
boost::shared_ptr<void> abi_test_2( boost::shared_ptr<void> const & p );
boost::shared_ptr<void> abi_test_3();
static int deleter_called;
void deleter( void* )
{
++deleter_called;
}
int main()
{
{
deleter_called = 0;
boost::shared_ptr<void> p( static_cast<void*>( 0 ), deleter );
BOOST_TEST_EQ( p.use_count(), 1 );
abi_test_1( p );
BOOST_TEST_EQ( p.use_count(), 0 );
BOOST_TEST_EQ( deleter_called, 1 );
}
{
deleter_called = 0;
boost::shared_ptr<void> p1( static_cast<void*>( 0 ), deleter );
BOOST_TEST_EQ( p1.use_count(), 1 );
boost::shared_ptr<void> p2 = abi_test_2( p1 );
BOOST_TEST_EQ( p1.use_count(), 2 );
BOOST_TEST_EQ( p2.use_count(), 2 );
p1.reset();
BOOST_TEST_EQ( p2.use_count(), 1 );
p2.reset();
BOOST_TEST_EQ( deleter_called, 1 );
}
{
boost::shared_ptr<void> p = abi_test_3();
BOOST_TEST_EQ( p.use_count(), 1 );
p.reset();
BOOST_TEST_EQ( p.use_count(), 0 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,165 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
struct allow { };
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
template<class U>
void construct(U* ptr) {
::new(static_cast<void*>(ptr)) U(allow());
}
template<class U>
void destroy(U* ptr) {
ptr->~U();
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
explicit type(allow) {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
{
boost::local_shared_ptr<type[]> result =
boost::allocate_local_shared<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[3]> result =
boost::allocate_local_shared<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[][2]> result =
boost::allocate_local_shared<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[2][2]> result =
boost::allocate_local_shared<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[]> result =
boost::allocate_local_shared<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[3]> result =
boost::allocate_local_shared<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[][2]> result =
boost::allocate_local_shared<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[2][2]> result =
boost::allocate_local_shared<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,103 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type
: public boost::enable_shared_from_this<type> {
public:
static unsigned instances;
type() {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
BOOST_TEST(type::instances == 0);
{
boost::local_shared_ptr<type[]> result =
boost::allocate_local_shared<type[]>(creator<type>(), 3);
try {
result[0].shared_from_this();
BOOST_ERROR("shared_from_this did not throw");
} catch (...) {
BOOST_TEST(type::instances == 3);
}
}
BOOST_TEST(type::instances == 0);
{
boost::local_shared_ptr<type[]> result =
boost::allocate_local_shared_noinit<type[]>(creator<>(), 3);
try {
result[0].shared_from_this();
BOOST_ERROR("shared_from_this did not throw");
} catch (...) {
BOOST_TEST(type::instances == 3);
}
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,254 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/align/is_aligned.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
boost::local_shared_ptr<int[]> result =
boost::allocate_local_shared_noinit<int[]>(creator<int>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<int[3]> result =
boost::allocate_local_shared_noinit<int[3]>(creator<int>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<int[][2]> result =
boost::allocate_local_shared_noinit<int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<int[2][2]> result =
boost::allocate_local_shared_noinit<int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<const int[]> result =
boost::allocate_local_shared_noinit<const int[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<const int[3]> result =
boost::allocate_local_shared_noinit<const int[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<const int[][2]> result =
boost::allocate_local_shared_noinit<const int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<const int[2][2]> result =
boost::allocate_local_shared_noinit<const int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::local_shared_ptr<type[]> result =
boost::allocate_local_shared_noinit<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[3]> result =
boost::allocate_local_shared_noinit<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[][2]> result =
boost::allocate_local_shared_noinit<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<type[][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[2][2]> result =
boost::allocate_local_shared_noinit<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<type[2][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[]> result =
boost::allocate_local_shared_noinit<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<const type[]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[3]> result =
boost::allocate_local_shared_noinit<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<const type[3]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[][2]> result =
boost::allocate_local_shared_noinit<const
type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<const type[][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[2][2]> result =
boost::allocate_local_shared_noinit<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<const type[2][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,275 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/align/is_aligned.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
boost::local_shared_ptr<int[]> result =
boost::allocate_local_shared<int[]>(creator<int>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::local_shared_ptr<int[3]> result =
boost::allocate_local_shared<int[3]>(creator<int>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::local_shared_ptr<int[][2]> result =
boost::allocate_local_shared<int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::local_shared_ptr<int[2][2]> result =
boost::allocate_local_shared<int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::local_shared_ptr<const int[]> result =
boost::allocate_local_shared<const int[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::local_shared_ptr<const int[3]> result =
boost::allocate_local_shared<const int[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::local_shared_ptr<const int[][2]> result =
boost::allocate_local_shared<const int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::local_shared_ptr<const int[2][2]> result =
boost::allocate_local_shared<const int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::local_shared_ptr<type[]> result =
boost::allocate_local_shared<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[3]> result =
boost::allocate_local_shared<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[][2]> result =
boost::allocate_local_shared<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<type[2][2]> result =
boost::allocate_local_shared<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[]> result =
boost::allocate_local_shared<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[3]> result =
boost::allocate_local_shared<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[][2]> result =
boost::allocate_local_shared<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::local_shared_ptr<const type[2][2]> result =
boost::allocate_local_shared<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.local_use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,130 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type() {
if (instances == 5) {
throw true;
}
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
try {
boost::allocate_local_shared<type[]>(creator<type>(), 6);
BOOST_ERROR("allocate_local_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared<type[][2]>(creator<type>(), 3);
BOOST_ERROR("allocate_local_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared<type[6]>(creator<>());
BOOST_ERROR("allocate_local_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared<type[3][2]>(creator<>());
BOOST_ERROR("allocate_local_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared_noinit<type[]>(creator<>(), 6);
BOOST_ERROR("allocate_local_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared_noinit<type[][2]>(creator<>(), 3);
BOOST_ERROR("allocate_local_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared_noinit<type[6]>(creator<>());
BOOST_ERROR("allocate_local_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_local_shared_noinit<type[3][2]>(creator<>());
BOOST_ERROR("allocate_local_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,92 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
int main()
{
{
boost::local_shared_ptr<int[]> result =
boost::allocate_local_shared<int[]>(creator<int>(), 4, 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
boost::local_shared_ptr<int[4]> result =
boost::allocate_local_shared<int[4]>(creator<int>(), 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
boost::local_shared_ptr<const int[]> result =
boost::allocate_local_shared<const int[]>(creator<>(), 4, 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
boost::local_shared_ptr<const int[4]> result =
boost::allocate_local_shared<const int[4]>(creator<>(), 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,93 @@
/*
Copyright 2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
int main()
{
{
boost::local_shared_ptr<int[][2]> result =
boost::allocate_local_shared<int[][2]>(creator<int>(), 2, {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
boost::local_shared_ptr<int[2][2]> result =
boost::allocate_local_shared<int[2][2]>(creator<int>(), {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
boost::local_shared_ptr<const int[][2]> result =
boost::allocate_local_shared<const int[][2]>(creator<>(), 2, {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
boost::local_shared_ptr<const int[2][2]> result =
boost::allocate_local_shared<const int[2][2]>(creator<>(), {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,298 @@
// allocate_local_shared_esft_test.cpp
//
// Copyright 2007-2009, 2017 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/config.hpp>
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
int main()
{
}
#else
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <memory>
class X: public boost::enable_shared_from_this<X>
{
private:
X( X const & );
X & operator=( X const & );
public:
static int instances;
explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 )
{
++instances;
}
~X()
{
--instances;
}
};
int X::instances = 0;
int main()
{
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>() );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared_noinit< X >( std::allocator<void>() );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
{
boost::shared_ptr< X > px = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
BOOST_TEST_EQ( X::instances, 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST_EQ( px, qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST_EQ( X::instances, 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST_EQ( X::instances, 0 );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,235 @@
// allocate_local_shared_test.cpp
//
// Copyright 2007-2009, 2017 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/config.hpp>
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
int main()
{
}
#else
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_local_shared.hpp>
#include <boost/smart_ptr/local_shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <cstddef>
class X
{
private:
X( X const & );
X & operator=( X const & );
void * operator new( std::size_t n )
{
// lack of this definition causes link errors on Comeau C++
BOOST_ERROR( "private X::new called" );
return ::operator new( n );
}
void operator delete( void * p )
{
// lack of this definition causes link errors on MSVC
BOOST_ERROR( "private X::delete called" );
::operator delete( 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::local_shared_ptr< int > pi = boost::allocate_local_shared< int >( std::allocator<int>() );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( *pi == 0 );
}
{
boost::local_shared_ptr< int > pi = boost::allocate_local_shared_noinit< int >( std::allocator<int>() );
BOOST_TEST( pi.get() != 0 );
}
{
boost::local_shared_ptr< int > pi = boost::allocate_local_shared< int >( std::allocator<int>(), 5 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( *pi == 5 );
}
BOOST_TEST( X::instances == 0 );
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>() );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 0 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared_noinit< X >( std::allocator<void>() );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 0 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::local_shared_ptr< X > pi = boost::allocate_local_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,241 @@
// allocate_shared_alloc11_test.cpp
//
// allocate_shared with a minimal C++11 allocator
//
// Copyright 2007-2009, 2014 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/core/lightweight_test.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/config.hpp>
#include <cstddef>
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
template< class T > class cxx11_allocator
{
public:
typedef T value_type;
cxx11_allocator()
{
}
template< class Y > cxx11_allocator( cxx11_allocator<Y> const & )
{
}
T * allocate( std::size_t n )
{
return static_cast< T* >( ::operator new( n * sizeof( T ) ) );
}
void deallocate( T * p, std::size_t n )
{
::operator delete( p );
}
};
class X
{
private:
X( X const & );
X & operator=( X const & );
void * operator new( std::size_t n )
{
BOOST_ERROR( "private X::new called" );
return ::operator new( n );
}
void operator delete( void * p )
{
BOOST_ERROR( "private X::delete called" );
::operator delete( 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::shared_ptr< int > pi = boost::allocate_shared< int >( cxx11_allocator<int>() );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( *pi == 0 );
}
{
boost::shared_ptr< int > pi = boost::allocate_shared< int >( cxx11_allocator<int>(), 5 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( *pi == 5 );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>() );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 0 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
return boost::report_errors();
}
#else // !defined( BOOST_NO_CXX11_ALLOCATOR )
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,163 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
struct allow { };
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
template<class U>
void construct(U* ptr) {
::new(static_cast<void*>(ptr)) U(allow());
}
template<class U>
void destroy(U* ptr) {
ptr->~U();
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
explicit type(allow) {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
{
boost::shared_ptr<type[]> result =
boost::allocate_shared<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[3]> result =
boost::allocate_shared<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[][2]> result =
boost::allocate_shared<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[2][2]> result =
boost::allocate_shared<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[]> result =
boost::allocate_shared<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[3]> result =
boost::allocate_shared<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[][2]> result =
boost::allocate_shared<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[2][2]> result =
boost::allocate_shared<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,94 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include <boost/smart_ptr/make_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type
: public boost::enable_shared_from_this<type> {
public:
static unsigned instances;
type() {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> result =
boost::allocate_shared<type[]>(creator<type>(), 3);
try {
result[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[]> result =
boost::allocate_shared_noinit<type[]>(creator<>(), 3);
try {
result[0].shared_from_this();
BOOST_ERROR("shared_from_this did not throw");
} catch (...) {
BOOST_TEST(type::instances == 3);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,245 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/align/is_aligned.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
boost::shared_ptr<int[]> result =
boost::allocate_shared_noinit<int[]>(creator<int>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<int[3]> result =
boost::allocate_shared_noinit<int[3]>(creator<int>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<int[][2]> result =
boost::allocate_shared_noinit<int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<int[2][2]> result =
boost::allocate_shared_noinit<int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<const int[]> result =
boost::allocate_shared_noinit<const int[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<const int[3]> result =
boost::allocate_shared_noinit<const int[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<const int[][2]> result =
boost::allocate_shared_noinit<const int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<const int[2][2]> result =
boost::allocate_shared_noinit<const int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
}
{
boost::shared_ptr<type[]> result =
boost::allocate_shared_noinit<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[3]> result =
boost::allocate_shared_noinit<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[][2]> result =
boost::allocate_shared_noinit<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<type[][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[2][2]> result =
boost::allocate_shared_noinit<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<type[2][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[]> result =
boost::allocate_shared_noinit<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<const type[]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[3]> result =
boost::allocate_shared_noinit<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<const type[3]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[][2]> result =
boost::allocate_shared_noinit<const
type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<const type[][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[2][2]> result =
boost::allocate_shared_noinit<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
boost::weak_ptr<const type[2][2]> other = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,266 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/align/is_aligned.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
boost::shared_ptr<int[]> result =
boost::allocate_shared<int[]>(creator<int>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::shared_ptr<int[3]> result =
boost::allocate_shared<int[3]>(creator<int>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::shared_ptr<int[][2]> result =
boost::allocate_shared<int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::shared_ptr<int[2][2]> result =
boost::allocate_shared<int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::shared_ptr<const int[]> result =
boost::allocate_shared<const int[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::shared_ptr<const int[3]> result =
boost::allocate_shared<const int[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
boost::shared_ptr<const int[][2]> result =
boost::allocate_shared<const int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::shared_ptr<const int[2][2]> result =
boost::allocate_shared<const int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<int>::value));
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
boost::shared_ptr<type[]> result =
boost::allocate_shared<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[3]> result =
boost::allocate_shared<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = result;
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[][2]> result =
boost::allocate_shared<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<type[2][2]> result =
boost::allocate_shared<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[]> result =
boost::allocate_shared<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[3]> result =
boost::allocate_shared<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[][2]> result =
boost::allocate_shared<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
boost::shared_ptr<const type[2][2]> result =
boost::allocate_shared<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result.use_count() == 1);
BOOST_TEST(boost::alignment::is_aligned(result.get(),
boost::alignment_of<type>::value));
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,121 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type() {
if (instances == 5) {
throw true;
}
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
try {
boost::allocate_shared<type[]>(creator<type>(), 6);
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared<type[][2]>(creator<type>(), 3);
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared<type[6]>(creator<>());
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared<type[3][2]>(creator<>());
BOOST_ERROR("allocate_shared did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared_noinit<type[]>(creator<>(), 6);
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared_noinit<type[][2]>(creator<>(), 3);
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared_noinit<type[6]>(creator<>());
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_shared_noinit<type[3][2]>(creator<>());
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,83 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
int main()
{
{
boost::shared_ptr<int[]> result =
boost::allocate_shared<int[]>(creator<int>(), 4, 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
boost::shared_ptr<int[4]> result =
boost::allocate_shared<int[4]>(creator<int>(), 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
boost::shared_ptr<const int[]> result =
boost::allocate_shared<const int[]>(creator<>(), 4, 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
boost::shared_ptr<const int[4]> result =
boost::allocate_shared<const int[4]>(creator<>(), 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,91 @@
/*
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared.hpp>
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
int main()
{
{
boost::shared_ptr<int[][2]> result =
boost::allocate_shared<int[][2]>(creator<int>(), 2, {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
boost::shared_ptr<int[2][2]> result =
boost::allocate_shared<int[2][2]>(creator<int>(), {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
boost::shared_ptr<const int[][2]> result =
boost::allocate_shared<const int[][2]>(creator<>(), 2, {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
boost::shared_ptr<const int[2][2]> result =
boost::allocate_shared<const int[2][2]>(creator<>(), {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,240 @@
// allocate_shared_construct11_test.cpp
//
// Test whether allocate_shared uses construct/destroy in C++11
//
// Copyright 2007-2009, 2014 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/core/lightweight_test.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <cstddef>
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
template< class T > class cxx11_allocator
{
public:
typedef T value_type;
cxx11_allocator()
{
}
template< class Y > cxx11_allocator( cxx11_allocator<Y> const & )
{
}
T * allocate( std::size_t n )
{
return static_cast< T* >( ::operator new( n * sizeof( T ) ) );
}
void deallocate( T * p, std::size_t n )
{
::operator delete( p );
}
template<class... Args> void construct( T * p, Args&&... args )
{
::new( static_cast< void* >( p ) ) T( std::forward<Args>( args )... );
}
void destroy( T * p )
{
p->~T();
}
};
class X
{
private:
X( X const & );
X & operator=( X const & );
void * operator new( std::size_t n )
{
BOOST_ERROR( "private X::new called" );
return ::operator new( n );
}
void operator delete( void * p )
{
BOOST_ERROR( "private X::delete called" );
::operator delete( p );
}
public:
static int instances;
int v;
protected:
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;
}
friend class cxx11_allocator<X>;
};
int X::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>() );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 0 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( cxx11_allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
return boost::report_errors();
}
#else // !defined( BOOST_NO_CXX11_ALLOCATOR )
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,286 @@
// allocate_shared_esft_test.cpp
//
// Copyright 2007-2009 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/core/lightweight_test.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <memory>
class X: public boost::enable_shared_from_this<X>
{
private:
X( X const & );
X & operator=( X const & );
public:
static int instances;
explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 )
{
++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<void>() );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared_noinit< X >( std::allocator<void>() );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > px = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
BOOST_TEST( X::instances == 1 );
try
{
boost::shared_ptr< X > qx = px->shared_from_this();
BOOST_TEST( px == qx );
BOOST_TEST( !( px < qx ) && !( qx < px ) );
px.reset();
BOOST_TEST( X::instances == 1 );
}
catch( boost::bad_weak_ptr const& )
{
BOOST_ERROR( "px->shared_from_this() failed" );
}
}
BOOST_TEST( X::instances == 0 );
return boost::report_errors();
}

View File

@@ -0,0 +1,223 @@
// allocate_shared_test.cpp
//
// Copyright 2007-2009 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/core/lightweight_test.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <cstddef>
class X
{
private:
X( X const & );
X & operator=( X const & );
void * operator new( std::size_t n )
{
// lack of this definition causes link errors on Comeau C++
BOOST_ERROR( "private X::new called" );
return ::operator new( n );
}
void operator delete( void * p )
{
// lack of this definition causes link errors on MSVC
BOOST_ERROR( "private X::delete called" );
::operator delete( 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::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>() );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( *pi == 0 );
}
{
boost::shared_ptr< int > pi = boost::allocate_shared_noinit< int >( std::allocator<int>() );
BOOST_TEST( pi.get() != 0 );
}
{
boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator<int>(), 5 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( *pi == 5 );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>() );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 0 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared_noinit< X >( std::allocator<void>() );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 0 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
boost::weak_ptr<X> wp( pi );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( pi.get() != 0 );
BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 );
pi.reset();
BOOST_TEST( X::instances == 0 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,84 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 46000) && \
!defined(BOOST_NO_CXX11_SMART_PTR) && \
!defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
struct type {
int x;
int y;
};
int main()
{
{
std::unique_ptr<type,
boost::alloc_deleter<type, creator<type> > > result =
boost::allocate_unique<type>(creator<type>(), { 1, 2 });
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->x == 1);
BOOST_TEST(result->y == 2);
}
{
std::unique_ptr<const type,
boost::alloc_deleter<const type, creator<> > > result =
boost::allocate_unique<const type>(creator<>(), { 1, 2 });
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->x == 1);
BOOST_TEST(result->y == 2);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,111 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 46000) && \
!defined(BOOST_NO_CXX11_SMART_PTR) && \
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type(int v1, int v2, int v3, int v4, int v5)
: sum_(v1 + v2 + v3 + v4 + v5) {
++instances;
}
~type() {
--instances;
}
int sum() const {
return sum_;
}
private:
int sum_;
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type,
boost::alloc_deleter<type, creator<type> > > result =
boost::allocate_unique<type>(creator<type>(), 1, 2, 3, 4, 5);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(result->sum() == 15);
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type,
boost::alloc_deleter<const type, creator<> > > result =
boost::allocate_unique<const type>(creator<>(), 1, 2, 3, 4, 5);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(result->sum() == 15);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,166 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 48000) && \
!defined(BOOST_NO_CXX11_SMART_PTR) && \
!defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
struct allow { };
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
template<class U>
void construct(U* ptr) {
::new(static_cast<void*>(ptr)) U(allow());
}
template<class U>
void destroy(U* ptr) {
ptr->~U();
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
explicit type(allow) {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<type[],
boost::alloc_deleter<type[], creator<type> > > result =
boost::allocate_unique<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[],
boost::alloc_deleter<type[3], creator<type> > > result =
boost::allocate_unique<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[][2],
boost::alloc_deleter<type[][2], creator<> > > result =
boost::allocate_unique<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[][2],
boost::alloc_deleter<type[2][2], creator<> > > result =
boost::allocate_unique<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[],
boost::alloc_deleter<const type[], creator<> > > result =
boost::allocate_unique<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[],
boost::alloc_deleter<const type[3], creator<> > > result =
boost::allocate_unique<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[][2],
boost::alloc_deleter<const type[][2], creator<> > > result =
boost::allocate_unique<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[][2],
boost::alloc_deleter<const type[2][2], creator<> > > result =
boost::allocate_unique<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,228 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 48000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int[],
boost::alloc_deleter<int[],
boost::noinit_adaptor<creator<int> > > > result =
boost::allocate_unique_noinit<int[]>(creator<int>(), 3);
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<int[],
boost::alloc_deleter<int[3],
boost::noinit_adaptor<creator<int> > > > result =
boost::allocate_unique_noinit<int[3]>(creator<int>());
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<int[][2],
boost::alloc_deleter<int[][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<int[][2],
boost::alloc_deleter<int[2][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<const int[],
boost::alloc_deleter<const int[],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const int[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<const int[],
boost::alloc_deleter<const int[3],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const int[3]>(creator<>());
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<const int[][2],
boost::alloc_deleter<const int[][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<const int[][2],
boost::alloc_deleter<const int[2][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<type[],
boost::alloc_deleter<type[],
boost::noinit_adaptor<creator<type> > > > result =
boost::allocate_unique_noinit<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[],
boost::alloc_deleter<type[3],
boost::noinit_adaptor<creator<type> > > > result =
boost::allocate_unique_noinit<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[][2],
boost::alloc_deleter<type[][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[][2],
boost::alloc_deleter<type[2][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[],
boost::alloc_deleter<const type[],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[],
boost::alloc_deleter<const type[3],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[][2],
boost::alloc_deleter<const type[][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[][2],
boost::alloc_deleter<const type[2][2],
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,240 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 48000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int[],
boost::alloc_deleter<int[], creator<int> > > result =
boost::allocate_unique<int[]>(creator<int>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
std::unique_ptr<int[],
boost::alloc_deleter<int[3], creator<int> > > result =
boost::allocate_unique<int[3]>(creator<int>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
std::unique_ptr<int[][2],
boost::alloc_deleter<int[][2], creator<> > > result =
boost::allocate_unique<int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
std::unique_ptr<int[][2],
boost::alloc_deleter<int[2][2], creator<> > > result =
boost::allocate_unique<int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
std::unique_ptr<const int[],
boost::alloc_deleter<const int[], creator<> > > result =
boost::allocate_unique<const int[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
std::unique_ptr<const int[],
boost::alloc_deleter<const int[3], creator<> > > result =
boost::allocate_unique<const int[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
std::unique_ptr<const int[][2],
boost::alloc_deleter<const int[][2], creator<> > > result =
boost::allocate_unique<const int[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
std::unique_ptr<const int[][2],
boost::alloc_deleter<const int[2][2], creator<> > > result =
boost::allocate_unique<const int[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
std::unique_ptr<type[],
boost::alloc_deleter<type[], creator<type> > > result =
boost::allocate_unique<type[]>(creator<type>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[],
boost::alloc_deleter<type[3], creator<type> > > result =
boost::allocate_unique<type[3]>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[][2],
boost::alloc_deleter<type[][2], creator<> > > result =
boost::allocate_unique<type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type[][2],
boost::alloc_deleter<type[2][2], creator<> > > result =
boost::allocate_unique<type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[],
boost::alloc_deleter<const type[], creator<> > > result =
boost::allocate_unique<const type[]>(creator<>(), 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[],
boost::alloc_deleter<const type[3], creator<> > > result =
boost::allocate_unique<const type[3]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[][2],
boost::alloc_deleter<const type[][2], creator<> > > result =
boost::allocate_unique<const type[][2]>(creator<>(), 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type[][2],
boost::alloc_deleter<const type[2][2], creator<> > > result =
boost::allocate_unique<const type[2][2]>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,132 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 48000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type() {
if (instances == 5) {
throw true;
}
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
try {
boost::allocate_unique<type[]>(creator<type>(), 6);
BOOST_ERROR("allocate_unique did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique<type[][2]>(creator<type>(), 3);
BOOST_ERROR("allocate_unique did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique<type[6]>(creator<>());
BOOST_ERROR("allocate_unique did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique<type[3][2]>(creator<>());
BOOST_ERROR("allocate_unique did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique_noinit<type[]>(creator<>(), 6);
BOOST_ERROR("allocate_unique_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique_noinit<type[][2]>(creator<>(), 3);
BOOST_ERROR("allocate_unique_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique_noinit<type[6]>(creator<>());
BOOST_ERROR("allocate_unique_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique_noinit<type[3][2]>(creator<>());
BOOST_ERROR("allocate_unique_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,98 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 48000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
int main()
{
{
std::unique_ptr<int[],
boost::alloc_deleter<int[], creator<int> > > result =
boost::allocate_unique<int[]>(creator<int>(), 4, 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
std::unique_ptr<int[],
boost::alloc_deleter<int[4], creator<int> > > result =
boost::allocate_unique<int[4]>(creator<int>(), 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
std::unique_ptr<const int[],
boost::alloc_deleter<const int[], creator<> > > result =
boost::allocate_unique<const int[]>(creator<>(), 4, 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
{
std::unique_ptr<const int[],
boost::alloc_deleter<const int[4], creator<> > > result =
boost::allocate_unique<const int[4]>(creator<>(), 1);
BOOST_TEST(result[0] == 1);
BOOST_TEST(result[1] == 1);
BOOST_TEST(result[2] == 1);
BOOST_TEST(result[3] == 1);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,99 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 48000) && \
!defined(BOOST_NO_CXX11_SMART_PTR) && \
!defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
int main()
{
{
std::unique_ptr<int[][2],
boost::alloc_deleter<int[][2], creator<int> > > result =
boost::allocate_unique<int[][2]>(creator<int>(), 2, {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
std::unique_ptr<int[][2],
boost::alloc_deleter<int[2][2], creator<int> > > result =
boost::allocate_unique<int[2][2]>(creator<int>(), {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
std::unique_ptr<const int[][2],
boost::alloc_deleter<const int[][2], creator<> > > result =
boost::allocate_unique<const int[][2]>(creator<>(), 2, {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
{
std::unique_ptr<const int[][2],
boost::alloc_deleter<const int[2][2], creator<> > > result =
boost::allocate_unique<const int[2][2]>(creator<>(), {0, 1});
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 1);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 1);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,109 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
struct allow { };
template<class T = void>
struct creator {
typedef T value_type;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
template<class U>
void construct(U* ptr) {
::new(static_cast<void*>(ptr)) U(allow());
}
template<class U>
void destroy(U* ptr) {
ptr->~U();
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
explicit type(allow) {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<type,
boost::alloc_deleter<type, creator<type> > > result =
boost::allocate_unique<type>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type,
boost::alloc_deleter<const type, creator<> > > result =
boost::allocate_unique<const type>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,126 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 46000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type()
: value_(0.0) {
++instances;
}
~type() {
--instances;
}
void set(long double value) {
value_ = value;
}
long double get() const {
return value_;
}
private:
type(const type&);
type& operator=(const type&);
long double value_;
};
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int,
boost::alloc_deleter<int,
boost::noinit_adaptor<creator<int> > > > result =
boost::allocate_unique_noinit<int>(creator<int>());
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<const int,
boost::alloc_deleter<const int,
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const int>(creator<>());
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<type,
boost::alloc_deleter<type,
boost::noinit_adaptor<creator<type> > > > result =
boost::allocate_unique_noinit<type>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<const type,
boost::alloc_deleter<const type,
boost::noinit_adaptor<creator<> > > > result =
boost::allocate_unique_noinit<const type>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,115 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 46000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type() {
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int,
boost::alloc_deleter<int, creator<int> > > result =
boost::allocate_unique<int>(creator<int>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(*result == 0);
}
{
std::unique_ptr<const int,
boost::alloc_deleter<const int, creator<> > > result =
boost::allocate_unique<const int>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(*result == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type,
boost::alloc_deleter<type, creator<type> > > result =
boost::allocate_unique<type>(creator<type>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type,
boost::alloc_deleter<const type, creator<> > > result =
boost::allocate_unique<const type>(creator<>());
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,96 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 46000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
static unsigned instances;
type() {
if (instances == 0) {
throw true;
}
++instances;
}
~type() {
--instances;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned type::instances = 0;
int main()
{
try {
boost::allocate_unique<type>(creator<type>());
BOOST_ERROR("allocate_unique did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
try {
boost::allocate_unique<const type>(creator<>());
BOOST_ERROR("allocate_unique did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,103 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if (!defined(BOOST_LIBSTDCXX_VERSION) || \
BOOST_LIBSTDCXX_VERSION >= 46000) && \
!defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/smart_ptr/allocate_unique.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T = void>
struct creator {
typedef T value_type;
typedef T* pointer;
template<class U>
struct rebind {
typedef creator<U> other;
};
creator() { }
template<class U>
creator(const creator<U>&) { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
inline bool
operator==(const creator<T>&, const creator<U>&)
{
return true;
}
template<class T, class U>
inline bool
operator!=(const creator<T>&, const creator<U>&)
{
return false;
}
class type {
public:
type(int x, int y)
: value_(x + y) { }
int sum() const {
return value_;
}
private:
int value_;
};
int main()
{
{
std::unique_ptr<int,
boost::alloc_deleter<int, creator<int> > > result =
boost::allocate_unique<int>(creator<int>(), 1);
BOOST_TEST(result.get() != 0);
BOOST_TEST(*result == 1);
}
{
std::unique_ptr<const int,
boost::alloc_deleter<const int, creator<> > > result =
boost::allocate_unique<const int>(creator<>(), 1);
BOOST_TEST(result.get() != 0);
BOOST_TEST(*result == 1);
}
{
std::unique_ptr<type,
boost::alloc_deleter<type, creator<type> > > result =
boost::allocate_unique<type>(creator<type>(), type(1, 2));
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->sum() == 3);
}
{
std::unique_ptr<const type,
boost::alloc_deleter<const type, creator<> > > result =
boost::allocate_unique<const type>(creator<>(), type(1, 2));
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->sum() == 3);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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>();
}

View File

@@ -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>() ));
}

View File

@@ -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
{
};
template<class T> void f( T & /*t*/ )
{
}
int main()
{
boost::shared_ptr<X> px( new X );
f( px[ 0 ] );
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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>();
}

View File

@@ -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>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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>();
}

View File

@@ -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>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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>();
}

View File

@@ -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>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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>();
}

View File

@@ -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>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -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;
}

View File

@@ -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 );
}

View File

@@ -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[]>();
}

View File

@@ -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[]>() ));
}

View File

@@ -0,0 +1,40 @@
// Copyright 2018, 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt)
#include <boost/smart_ptr/detail/atomic_count.hpp>
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
static boost::detail::atomic_count count( 0 );
void f( int n )
{
for( int i = 0; i < n; ++i )
{
++count;
}
}
int main()
{
int const N = 100000; // iterations
int const M = 8; // threads
boost::detail::lw_thread_t th[ M ] = {};
for( int i = 0; i < M; ++i )
{
boost::detail::lw_thread_create( th[ i ], boost::bind( f, N ) );
}
for( int i = 0; i < M; ++i )
{
boost::detail::lw_thread_join( th[ i ] );
}
BOOST_TEST_EQ( count, N * M );
return boost::report_errors();
}

View File

@@ -0,0 +1,40 @@
//
// atomic_count_test.cpp
//
// Copyright 2005 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/atomic_count.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
boost::detail::atomic_count n( 4 );
BOOST_TEST( n == 4L );
++n;
BOOST_TEST( n == 5L );
BOOST_TEST( --n != 0L );
boost::detail::atomic_count m( 0 );
BOOST_TEST( m == 0 );
++m;
BOOST_TEST( m == 1 );
++m;
BOOST_TEST( m == 2 );
BOOST_TEST( --m != 0 );
BOOST_TEST( --m == 0 );
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
//
// atomic_count_test2.cpp
//
// Copyright 2009 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/atomic_count.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
boost::detail::atomic_count n( 4 );
BOOST_TEST( n == 4 );
BOOST_TEST( ++n == 5 );
BOOST_TEST( ++n == 6 );
BOOST_TEST( n == 6 );
BOOST_TEST( --n == 5 );
BOOST_TEST( --n == 4 );
BOOST_TEST( n == 4 );
boost::detail::atomic_count m( 0 );
BOOST_TEST( m == 0 );
BOOST_TEST( ++m == 1 );
BOOST_TEST( ++m == 2 );
BOOST_TEST( m == 2 );
BOOST_TEST( --m == 1 );
BOOST_TEST( --m == 0 );
BOOST_TEST( m == 0 );
BOOST_TEST( --m == -1 );
BOOST_TEST( --m == -2 );
BOOST_TEST( m == -2 );
BOOST_TEST( ++m == -1 );
BOOST_TEST( ++m == 0 );
BOOST_TEST( m == 0 );
return boost::report_errors();
}

View File

@@ -0,0 +1,77 @@
//
// atomic_sp_constexpr_test.cpp
//
// Copyright 2017, 2018 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/config.hpp>
#include <boost/config/workaround.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/helper_macros.hpp>
#if defined( BOOST_NO_CXX11_CONSTEXPR )
BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_CONSTEXPR")
int main() {}
#elif BOOST_WORKAROUND( BOOST_MSVC, < 1930 )
// MSVC does not implement static initialization for constexpr constructors
BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_MSVC < 1930")
int main() {}
#elif defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR )
// Clang only implements static initialization for constexpr in C++14 mode
BOOST_PRAGMA_MESSAGE("Skipping test due to __clang__ and BOOST_NO_CXX14_CONSTEXPR")
int main() {}
#elif defined( _LIBCPP_VERSION ) && ( _LIBCPP_VERSION < 6000 )
// in libc++, atomic_flag has a non-constexpr constructor from bool
BOOST_PRAGMA_MESSAGE("Skipping test due to _LIBCPP_VERSION " BOOST_STRINGIZE(_LIBCPP_VERSION))
int main() {}
#elif defined( BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX )
BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX")
int main() {}
#else
#include <boost/smart_ptr/atomic_shared_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
struct X
{
};
struct Z
{
Z();
};
static Z z;
static boost::atomic_shared_ptr<X> p1;
Z::Z()
{
p1 = boost::shared_ptr<X>( new X );
}
int main()
{
boost::shared_ptr<X> p2 = p1;
BOOST_TEST( p2.get() != 0 );
BOOST_TEST_EQ( p2.use_count(), 2 );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,325 @@
#include <boost/config.hpp>
// atomic_sp_test.cpp
//
// Copyright 2008, 2017 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/smart_ptr/atomic_shared_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/memory_order.hpp>
//
struct X
{
};
#define BOOST_TEST_SP_EQ( p, q ) BOOST_TEST( p == q && !( p < q ) && !( q < p ) )
int main()
{
// default constructor
{
boost::atomic_shared_ptr<X> apx;
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( p2.get(), (X*)0 );
BOOST_TEST_EQ( p2.use_count(), 0 );
}
// shared_ptr constructor
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// shared_ptr assignment
{
boost::shared_ptr<X> px0( new X );
boost::atomic_shared_ptr<X> apx( px0 );
boost::shared_ptr<X> px( new X );
apx = px;
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// load, w/ mo
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> p2 = apx.load( boost::memory_order_acquire );
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// operator shared_ptr
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> p2 = apx;
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// store
{
boost::shared_ptr<X> px0( new X );
boost::atomic_shared_ptr<X> apx( px0 );
boost::shared_ptr<X> px( new X );
apx.store( px );
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// store, w/ mo
{
boost::shared_ptr<X> px0( new X );
boost::atomic_shared_ptr<X> apx( px0 );
boost::shared_ptr<X> px( new X );
apx.store( px, boost::memory_order_release );
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// exchange
{
boost::shared_ptr<X> px0( new X );
boost::atomic_shared_ptr<X> apx( px0 );
boost::shared_ptr<X> px( new X );
boost::shared_ptr<X> p1 = apx.exchange( px );
BOOST_TEST_EQ( px0, p1 );
BOOST_TEST_EQ( px0.use_count(), 2 );
BOOST_TEST_EQ( p1.use_count(), 2 );
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// exchange, w/ mo
{
boost::shared_ptr<X> px0( new X );
boost::atomic_shared_ptr<X> apx( px0 );
boost::shared_ptr<X> px( new X );
boost::shared_ptr<X> p1 = apx.exchange( px, boost::memory_order_acq_rel );
BOOST_TEST_EQ( px0, p1 );
BOOST_TEST_EQ( px0.use_count(), 2 );
BOOST_TEST_EQ( p1.use_count(), 2 );
boost::shared_ptr<X> p2 = apx.load();
BOOST_TEST_EQ( px, p2 );
BOOST_TEST_EQ( px.use_count(), 3 );
BOOST_TEST_EQ( p2.use_count(), 3 );
}
// compare_exchange_weak
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> px2( new X );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_weak( cmp, px2 );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_weak( cmp, px2 );
BOOST_TEST( r );
BOOST_TEST_SP_EQ( apx.load(), px2 );
}
// compare_exchange_weak, w/ mo
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> px2( new X );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_weak( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_weak( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( r );
BOOST_TEST_SP_EQ( apx.load(), px2 );
}
// compare_exchange_weak, rv
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>() );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>() );
BOOST_TEST( r );
BOOST_TEST( apx.load().get() == 0 );
BOOST_TEST( apx.load().use_count() == 0 );
}
// compare_exchange_weak, rv, w/ mo
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_weak( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( r );
BOOST_TEST( apx.load().get() == 0 );
BOOST_TEST( apx.load().use_count() == 0 );
}
// compare_exchange_strong
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> px2( new X );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_strong( cmp, px2 );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_strong( cmp, px2 );
BOOST_TEST( r );
BOOST_TEST_SP_EQ( apx.load(), px2 );
}
// compare_exchange_strong, w/ mo
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> px2( new X );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_strong( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_strong( cmp, px2, boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( r );
BOOST_TEST_SP_EQ( apx.load(), px2 );
}
// compare_exchange_strong, rv
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>() );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>() );
BOOST_TEST( r );
BOOST_TEST( apx.load().get() == 0 );
BOOST_TEST( apx.load().use_count() == 0 );
}
// compare_exchange_strong, rv, w/ mo
{
boost::shared_ptr<X> px( new X );
boost::atomic_shared_ptr<X> apx( px );
boost::shared_ptr<X> cmp;
bool r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( !r );
BOOST_TEST_SP_EQ( apx.load(), px );
BOOST_TEST_SP_EQ( cmp, px );
r = apx.compare_exchange_strong( cmp, boost::shared_ptr<X>(), boost::memory_order_seq_cst, boost::memory_order_seq_cst );
BOOST_TEST( r );
BOOST_TEST( apx.load().get() == 0 );
BOOST_TEST( apx.load().use_count() == 0 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,32 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// auto_ptr_lv_fail.cpp - a negative test for converting an auto_ptr to shared_ptr
//
// Copyright 2009 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>
void f( boost::shared_ptr<int> )
{
}
int main()
{
std::auto_ptr<int> p;
f( p ); // must fail
return 0;
}

View File

@@ -0,0 +1,123 @@
#include <boost/config.hpp>
//
// auto_ptr_rv_test.cpp
//
// Copyright (c) 2006 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
//
#if defined( BOOST_NO_AUTO_PTR )
int main()
{
}
#else
#include <boost/shared_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
#include <memory>
struct X
{
static long instances;
X()
{
++instances;
}
~X()
{
--instances;
}
static std::auto_ptr<X> create()
{
return std::auto_ptr<X>( new X );
}
private:
X( X const & );
X & operator=( X const & );
};
long X::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<X> p( X::create() );
BOOST_TEST( X::instances == 1 );
p = X::create();
BOOST_TEST( X::instances == 1 );
p.reset();
BOOST_TEST( X::instances == 0 );
p = X::create();
BOOST_TEST( X::instances == 1 );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<X const> p( X::create() );
BOOST_TEST( X::instances == 1 );
p = X::create();
BOOST_TEST( X::instances == 1 );
p.reset();
BOOST_TEST( X::instances == 0 );
p = X::create();
BOOST_TEST( X::instances == 1 );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<void> p( X::create() );
BOOST_TEST( X::instances == 1 );
p = X::create();
BOOST_TEST( X::instances == 1 );
p.reset();
BOOST_TEST( X::instances == 0 );
p = X::create();
BOOST_TEST( X::instances == 1 );
}
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr<void const> p( X::create() );
BOOST_TEST( X::instances == 1 );
p = X::create();
BOOST_TEST( X::instances == 1 );
p.reset();
BOOST_TEST( X::instances == 0 );
p = X::create();
BOOST_TEST( X::instances == 1 );
}
BOOST_TEST( X::instances == 0 );
return boost::report_errors();
}
#endif // #if defined( BOOST_NO_AUTO_PTR )

View File

@@ -0,0 +1,18 @@
# Copyright 2018, 2019 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_subdir_test LANGUAGES CXX)
find_package(boost_smart_ptr REQUIRED)
find_package(boost_core REQUIRED)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::smart_ptr Boost::core)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@@ -0,0 +1,24 @@
# Copyright 2018, 2019 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/smart_ptr)
add_subdirectory(../../../assert boostorg/assert)
add_subdirectory(../../../config boostorg/config)
add_subdirectory(../../../core boostorg/core)
add_subdirectory(../../../move boostorg/move)
add_subdirectory(../../../static_assert boostorg/static_assert)
add_subdirectory(../../../throw_exception boostorg/throw_exception)
add_subdirectory(../../../type_traits boostorg/type_traits)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::smart_ptr Boost::core)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@@ -0,0 +1,99 @@
//
// collector_test.cpp
//
// Copyright (c) 2003 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 <vector>
#include <iostream>
#include <cstdlib>
#include <ctime>
// sp_collector.cpp exported functions
std::size_t find_unreachable_objects(bool report);
void free_unreachable_objects();
struct X
{
void* fill[32];
boost::shared_ptr<X> p;
};
void report()
{
std::cout << "Calling find_unreachable_objects:\n";
std::clock_t t = std::clock();
std::size_t n = find_unreachable_objects(false);
t = std::clock() - t;
std::cout << n << " unreachable objects.\n";
std::cout << " " << static_cast<double>(t) / CLOCKS_PER_SEC << " seconds.\n";
}
void free()
{
std::cout << "Calling free_unreachable_objects:\n";
std::clock_t t = std::clock();
free_unreachable_objects();
t = std::clock() - t;
std::cout << " " << static_cast<double>(t) / CLOCKS_PER_SEC << " seconds.\n";
}
int main()
{
std::vector< boost::shared_ptr<X> > v1, v2;
int const n = 256 * 1024;
std::cout << "Filling v1 and v2\n";
for(int i = 0; i < n; ++i)
{
v1.push_back(boost::shared_ptr<X>(new X));
v2.push_back(boost::shared_ptr<X>(new X));
}
report();
std::cout << "Creating the cycles\n";
for(int i = 0; i < n - 1; ++i)
{
v2[i]->p = v2[i+1];
}
v2[n-1]->p = v2[0];
report();
std::cout << "Resizing v2 to size of 1\n";
v2.resize(1);
report();
std::cout << "Clearing v2\n";
v2.clear();
report();
std::cout << "Clearing v1\n";
v1.clear();
report();
free();
report();
}

View File

@@ -0,0 +1,224 @@
//
// cpp11_pointer_cast_test.cpp - a test for boost/pointer_cast.hpp with std::shared_ptr and std::unique_ptr
//
// Copyright (c) 2016 Karolin Varner
//
// 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/pointer_cast.hpp>
#include <boost/config.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/get_pointer.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <utility>
#include <functional>
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) \
|| defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) \
|| defined( BOOST_NO_CXX11_HDR_UTILITY ) \
|| defined( BOOST_NO_CXX11_LAMBDAS ) \
|| defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
// We expect all the features or none of the features to be
// available, since we should be on C++11
int main() { return 0; }
#else
namespace
{
// Let's create these inheritance relationship:
//
// base base2
// | |
// derived
// |
// derived_derived
//
class base
{
public:
virtual ~base(){}
int filler [5];
};
class base2
{
public:
virtual ~base2(){}
int filler [5];
};
class derived
: public base, public base2
{
int filler [5];
};
class derived_derived
: public derived
{
int filler [5];
};
// And now some simple check functions
#if !defined( BOOST_NO_RTTI )
template <class BasePtr>
bool check_dynamic_pointer_cast(const BasePtr &ptr)
{
//Check that dynamic_pointer_cast versus dynamic_cast
return
//Correct cast with dynamic_pointer_cast
boost::get_pointer(boost::dynamic_pointer_cast<derived>(ptr)) ==
//Correct cast with dynamic_cast
dynamic_cast<derived*>(boost::get_pointer(ptr))
&&
//Incorrect cast with dynamic_pointer_cast
boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>(ptr)) ==
//Incorrect cast with dynamic_cast
dynamic_cast<derived_derived*>(boost::get_pointer(ptr));
}
#endif
template <class BasePtr>
bool check_static_pointer_cast(const BasePtr &ptr)
{
return
//Cast base -> derived -> base2 using static_pointer_cast
boost::get_pointer(
boost::static_pointer_cast<base2>(
boost::static_pointer_cast<derived>(ptr))) ==
//Now the same with static_cast
static_cast<base2*>(static_cast<derived*>(boost::get_pointer(ptr)));
}
template <class BasePtr>
bool check_const_pointer_cast(const BasePtr &ptr)
{
return
//Unconst and const again using const_pointer_cast
boost::get_pointer(
boost::const_pointer_cast<const base>
(boost::const_pointer_cast<base>(ptr))) ==
//Now the same with const_cast
const_cast<const base*>(const_cast<base*>(boost::get_pointer(ptr)));
}
template <class BasePtr>
void check_all_copy_casts(const BasePtr &ptr)
{
#if !defined( BOOST_NO_RTTI )
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
#endif
BOOST_TEST( check_static_pointer_cast( ptr ) );
BOOST_TEST( check_const_pointer_cast( ptr ) );
}
#if !defined( BOOST_NO_RTTI )
template <class BasePtr>
bool check_dynamic_moving_pointer_cast(std::function<BasePtr()> f)
{
BasePtr smart1 = f(), smart2 = f();
derived* expect1 = dynamic_cast<derived*>(boost::get_pointer(smart1));
derived_derived* expect2 = dynamic_cast<derived_derived*>(boost::get_pointer(smart2));
//Check that dynamic_pointer_cast versus dynamic_cast
return
//Correct cast with dynamic_pointer_cast
boost::get_pointer(boost::dynamic_pointer_cast<derived>( std::move(smart1) )) == expect1
&&
//Incorrect cast with dynamic_pointer_cast
boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>( std::move(smart2) )) == expect2;
}
#endif
template <class BasePtr>
bool check_static_moving_pointer_cast(std::function<BasePtr()> f)
{
BasePtr smart = f();
base2 *expect = static_cast<base2*>(static_cast<derived*>(boost::get_pointer(smart)));
return
//Cast base -> derived -> base2 using static_pointer_cast
boost::get_pointer(
boost::static_pointer_cast<base2>(
boost::static_pointer_cast<derived>( std::move(smart) ))) ==
//Now the same with static_cast
expect;
}
template <class BasePtr>
bool check_const_moving_pointer_cast(std::function<BasePtr()> f)
{
BasePtr smart = f();
const base *expect = const_cast<const base*>(const_cast<base*>(boost::get_pointer(smart)));
return
//Unconst and const again using const_pointer_cast
boost::get_pointer(
boost::const_pointer_cast<const base>
(boost::const_pointer_cast<base>( std::move(smart) ))) ==
//Now the same with const_cast
expect;
}
template <class BasePtr>
void check_all_moving_casts(std::function<BasePtr()> f) {
#if !defined( BOOST_NO_RTTI )
BOOST_TEST( check_dynamic_moving_pointer_cast( f ) );
#endif
BOOST_TEST( check_static_moving_pointer_cast( f ) );
BOOST_TEST( check_const_moving_pointer_cast( f ) );
}
}
int main()
{
std::shared_ptr<base> std_shared(new derived);
boost::shared_ptr<base> boost_shared(new derived);
base *plain = boost_shared.get();
// plain & boost::shared_ptr moving pointer_cast checks; there
// is no specific handleing for those types at the moment; this
// test just makes sure they won't break when std::move() is used
// in generic code
check_all_moving_casts<boost::shared_ptr<base>>([&boost_shared]() {
return boost_shared;
});
check_all_moving_casts<base*>([plain]() {
return plain;
});
// std::shared_ptr casts
check_all_copy_casts(std_shared);
check_all_moving_casts<std::shared_ptr<base>>([&std_shared]() {
return std_shared;
});
// std::unique_ptr casts
check_all_moving_casts<std::unique_ptr<base>>([]() {
return std::unique_ptr<base>(new derived);
});
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,42 @@
// Copyright 2018 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/make_shared.hpp>
#include <boost/config.hpp>
#include <memory>
#if defined(DLL_TEST_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
EXPORT boost::shared_ptr<int> dll_test_41()
{
return boost::shared_ptr<int>( new int( 41 ) );
}
EXPORT boost::shared_ptr<int> dll_test_42()
{
return boost::make_shared<int>( 42 );
}
EXPORT boost::shared_ptr<int> dll_test_43()
{
return boost::allocate_shared<int>( std::allocator<int>(), 43 );
}
EXPORT boost::shared_ptr<int[]> dll_test_44()
{
return boost::make_shared<int[1]>( 44 );
}
EXPORT boost::shared_ptr<int[]> dll_test_45()
{
return boost::allocate_shared<int[1]>( std::allocator<int>(), 45 );
}

Some files were not shown because too many files have changed in this diff Show More