forked from boostorg/smart_ptr
Merge branch 'develop'
This commit is contained in:
@ -111,8 +111,7 @@ struct sp_array_count<T[]> { };
|
|||||||
|
|
||||||
template<class D, class T>
|
template<class D, class T>
|
||||||
inline D*
|
inline D*
|
||||||
sp_get_deleter(const
|
sp_get_deleter(const boost::shared_ptr<T>& value) BOOST_NOEXCEPT_OR_NOTHROW
|
||||||
boost::shared_ptr<T>& value) BOOST_NOEXCEPT_OR_NOTHROW
|
|
||||||
{
|
{
|
||||||
return static_cast<D*>(value._internal_get_untyped_deleter());
|
return static_cast<D*>(value._internal_get_untyped_deleter());
|
||||||
}
|
}
|
||||||
@ -135,8 +134,7 @@ struct sp_max_size {
|
|||||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||||
template<class A, class T>
|
template<class A, class T>
|
||||||
struct sp_bind_allocator {
|
struct sp_bind_allocator {
|
||||||
typedef typename std::allocator_traits<A>::template
|
typedef typename std::allocator_traits<A>::template rebind_alloc<T> type;
|
||||||
rebind_alloc<T> type;
|
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
template<class A, class T>
|
template<class A, class T>
|
||||||
@ -154,13 +152,11 @@ struct sp_enable<true, T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<boost::has_trivial_destructor<T>::value>::type
|
||||||
typename sp_enable<boost::has_trivial_destructor<T>::value>::type
|
|
||||||
sp_array_destroy(T*, std::size_t) BOOST_NOEXCEPT { }
|
sp_array_destroy(T*, std::size_t) BOOST_NOEXCEPT { }
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<!boost::has_trivial_destructor<T>::value>::type
|
||||||
typename sp_enable<!boost::has_trivial_destructor<T>::value>::type
|
|
||||||
sp_array_destroy(T* storage, std::size_t size)
|
sp_array_destroy(T* storage, std::size_t size)
|
||||||
{
|
{
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
@ -181,8 +177,7 @@ sp_array_destroy(A& allocator, T* storage, std::size_t size)
|
|||||||
|
|
||||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<boost::has_trivial_constructor<T>::value ||
|
||||||
typename sp_enable<boost::has_trivial_constructor<T>::value ||
|
|
||||||
boost::has_trivial_destructor<T>::value>::type
|
boost::has_trivial_destructor<T>::value>::type
|
||||||
sp_array_construct(T* storage, std::size_t size)
|
sp_array_construct(T* storage, std::size_t size)
|
||||||
{
|
{
|
||||||
@ -192,8 +187,7 @@ sp_array_construct(T* storage, std::size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<!boost::has_trivial_constructor<T>::value &&
|
||||||
typename sp_enable<!boost::has_trivial_constructor<T>::value &&
|
|
||||||
!boost::has_trivial_destructor<T>::value>::type
|
!boost::has_trivial_destructor<T>::value>::type
|
||||||
sp_array_construct(T* storage, std::size_t size)
|
sp_array_construct(T* storage, std::size_t size)
|
||||||
{
|
{
|
||||||
@ -209,8 +203,7 @@ sp_array_construct(T* storage, std::size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<boost::has_trivial_copy_constructor<T>::value ||
|
||||||
typename sp_enable<boost::has_trivial_copy_constructor<T>::value ||
|
|
||||||
boost::has_trivial_destructor<T>::value>::type
|
boost::has_trivial_destructor<T>::value>::type
|
||||||
sp_array_construct(T* storage, std::size_t size, const T* list,
|
sp_array_construct(T* storage, std::size_t size, const T* list,
|
||||||
std::size_t count)
|
std::size_t count)
|
||||||
@ -221,8 +214,7 @@ sp_array_construct(T* storage, std::size_t size, const T* list,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<!boost::has_trivial_copy_constructor<T>::value &&
|
||||||
typename sp_enable<!boost::has_trivial_copy_constructor<T>::value &&
|
|
||||||
!boost::has_trivial_destructor<T>::value>::type
|
!boost::has_trivial_destructor<T>::value>::type
|
||||||
sp_array_construct(T* storage, std::size_t size, const T* list,
|
sp_array_construct(T* storage, std::size_t size, const T* list,
|
||||||
std::size_t count)
|
std::size_t count)
|
||||||
@ -315,14 +307,12 @@ sp_array_construct(A& allocator, T* storage, std::size_t size,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<boost::has_trivial_constructor<T>::value>::type
|
||||||
typename sp_enable<boost::has_trivial_constructor<T>::value>::type
|
|
||||||
sp_array_default(T*, std::size_t) BOOST_NOEXCEPT { }
|
sp_array_default(T*, std::size_t) BOOST_NOEXCEPT { }
|
||||||
|
|
||||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<!boost::has_trivial_constructor<T>::value &&
|
||||||
typename sp_enable<!boost::has_trivial_constructor<T>::value &&
|
|
||||||
boost::has_trivial_destructor<T>::value>::type
|
boost::has_trivial_destructor<T>::value>::type
|
||||||
sp_array_default(T* storage, std::size_t size)
|
sp_array_default(T* storage, std::size_t size)
|
||||||
{
|
{
|
||||||
@ -332,8 +322,7 @@ sp_array_default(T* storage, std::size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<!boost::has_trivial_constructor<T>::value &&
|
||||||
typename sp_enable<!boost::has_trivial_constructor<T>::value &&
|
|
||||||
!boost::has_trivial_destructor<T>::value>::type
|
!boost::has_trivial_destructor<T>::value>::type
|
||||||
sp_array_default(T* storage, std::size_t size)
|
sp_array_default(T* storage, std::size_t size)
|
||||||
{
|
{
|
||||||
@ -349,8 +338,7 @@ sp_array_default(T* storage, std::size_t size)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline typename sp_enable<!boost::has_trivial_constructor<T>::value>::type
|
||||||
typename sp_enable<!boost::has_trivial_constructor<T>::value>::type
|
|
||||||
sp_array_default(T* storage, std::size_t size)
|
sp_array_default(T* storage, std::size_t size)
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < size; ++i) {
|
for (std::size_t i = 0; i < size; ++i) {
|
||||||
@ -367,16 +355,16 @@ struct sp_less_align {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CONSTEXPR inline
|
BOOST_CONSTEXPR
|
||||||
typename sp_enable<sp_less_align<T, N>::value, std::size_t>::type
|
inline typename sp_enable<sp_less_align<T, N>::value, std::size_t>::type
|
||||||
sp_align(std::size_t size) BOOST_NOEXCEPT
|
sp_align(std::size_t size) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return (sizeof(T) * size + N - 1) & ~(N - 1);
|
return (sizeof(T) * size + N - 1) & ~(N - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CONSTEXPR inline
|
BOOST_CONSTEXPR
|
||||||
typename sp_enable<!sp_less_align<T, N>::value, std::size_t>::type
|
inline typename sp_enable<!sp_less_align<T, N>::value, std::size_t>::type
|
||||||
sp_align(std::size_t size) BOOST_NOEXCEPT
|
sp_align(std::size_t size) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return sizeof(T) * size;
|
return sizeof(T) * size;
|
||||||
@ -426,8 +414,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* construct(const T* list, std::size_t count) {
|
void* construct(const T* list, std::size_t count) {
|
||||||
sp_array_construct(reinterpret_cast<T*>(&storage_), N,
|
sp_array_construct(reinterpret_cast<T*>(&storage_), N, list, count);
|
||||||
list, count);
|
|
||||||
enabled_ = true;
|
enabled_ = true;
|
||||||
return &storage_;
|
return &storage_;
|
||||||
}
|
}
|
||||||
@ -463,30 +450,27 @@ public:
|
|||||||
|
|
||||||
~sp_size_array_destroyer() {
|
~sp_size_array_destroyer() {
|
||||||
if (enabled_) {
|
if (enabled_) {
|
||||||
sp_array_destroy(allocator_,
|
sp_array_destroy(allocator_, reinterpret_cast<T*>(&storage_), N);
|
||||||
reinterpret_cast<T*>(&storage_), N);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
void operator()(U) {
|
void operator()(U) {
|
||||||
if (enabled_) {
|
if (enabled_) {
|
||||||
sp_array_destroy(allocator_,
|
sp_array_destroy(allocator_, reinterpret_cast<T*>(&storage_), N);
|
||||||
reinterpret_cast<T*>(&storage_), N);
|
|
||||||
enabled_ = false;
|
enabled_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* construct() {
|
void* construct() {
|
||||||
sp_array_construct(allocator_,
|
sp_array_construct(allocator_, reinterpret_cast<T*>(&storage_), N);
|
||||||
reinterpret_cast<T*>(&storage_), N);
|
|
||||||
enabled_ = true;
|
enabled_ = true;
|
||||||
return &storage_;
|
return &storage_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* construct(const T* list, std::size_t count) {
|
void* construct(const T* list, std::size_t count) {
|
||||||
sp_array_construct(allocator_,
|
sp_array_construct(allocator_, reinterpret_cast<T*>(&storage_), N,
|
||||||
reinterpret_cast<T*>(&storage_), N, list, count);
|
list, count);
|
||||||
enabled_ = true;
|
enabled_ = true;
|
||||||
return &storage_;
|
return &storage_;
|
||||||
}
|
}
|
||||||
@ -573,8 +557,7 @@ public:
|
|||||||
static void operator_fn(U) BOOST_NOEXCEPT { }
|
static void operator_fn(U) BOOST_NOEXCEPT { }
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
sp_array_destroyer(const U& allocator, std::size_t size)
|
sp_array_destroyer(const U& allocator, std::size_t size) BOOST_NOEXCEPT
|
||||||
BOOST_NOEXCEPT
|
|
||||||
: allocator_(allocator),
|
: allocator_(allocator),
|
||||||
size_(size),
|
size_(size),
|
||||||
address_(0) { }
|
address_(0) { }
|
||||||
@ -592,16 +575,14 @@ public:
|
|||||||
|
|
||||||
~sp_array_destroyer() {
|
~sp_array_destroyer() {
|
||||||
if (address_) {
|
if (address_) {
|
||||||
sp_array_destroy(allocator_, static_cast<T*>(address_),
|
sp_array_destroy(allocator_, static_cast<T*>(address_), size_);
|
||||||
size_);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
void operator()(U) {
|
void operator()(U) {
|
||||||
if (address_) {
|
if (address_) {
|
||||||
sp_array_destroy(allocator_, static_cast<T*>(address_),
|
sp_array_destroy(allocator_, static_cast<T*>(address_), size_);
|
||||||
size_);
|
|
||||||
address_ = 0;
|
address_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,20 +636,18 @@ public:
|
|||||||
typename sp_bind_allocator<A, U>::type> other;
|
typename sp_bind_allocator<A, U>::type> other;
|
||||||
};
|
};
|
||||||
|
|
||||||
sp_array_allocator(const A& allocator, std::size_t size,
|
sp_array_allocator(const A& allocator, std::size_t size, void** result)
|
||||||
void** result) BOOST_NOEXCEPT
|
BOOST_NOEXCEPT
|
||||||
: allocator_(allocator),
|
: allocator_(allocator),
|
||||||
size_(size),
|
size_(size),
|
||||||
result_(result) { }
|
result_(result) { }
|
||||||
|
|
||||||
sp_array_allocator(const A& allocator, std::size_t size)
|
sp_array_allocator(const A& allocator, std::size_t size) BOOST_NOEXCEPT
|
||||||
BOOST_NOEXCEPT
|
|
||||||
: allocator_(allocator),
|
: allocator_(allocator),
|
||||||
size_(size) { }
|
size_(size) { }
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
sp_array_allocator(const sp_array_allocator<T, U>& other)
|
sp_array_allocator(const sp_array_allocator<T, U>& other) BOOST_NOEXCEPT
|
||||||
BOOST_NOEXCEPT
|
|
||||||
: allocator_(other.allocator_),
|
: allocator_(other.allocator_),
|
||||||
size_(other.size_),
|
size_(other.size_),
|
||||||
result_(other.result_) { }
|
result_(other.result_) { }
|
||||||
@ -956,8 +935,8 @@ allocate_shared(const A& allocator,
|
|||||||
shared_ptr<T> result(static_cast<type*>(0),
|
shared_ptr<T> result(static_cast<type*>(0),
|
||||||
detail::sp_inplace_tag<deleter>(), allocator);
|
detail::sp_inplace_tag<deleter>(), allocator);
|
||||||
deleter* state = detail::sp_get_deleter<deleter>(result);
|
deleter* state = detail::sp_get_deleter<deleter>(result);
|
||||||
void* start = state->construct(reinterpret_cast<const
|
void* start = state->construct(reinterpret_cast<const scalar*>(&value),
|
||||||
scalar*>(&value), detail::sp_array_count<type>::value);
|
detail::sp_array_count<type>::value);
|
||||||
return shared_ptr<T>(result, static_cast<type*>(start));
|
return shared_ptr<T>(result, static_cast<type*>(start));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
@ -36,7 +37,8 @@ namespace boost
|
|||||||
# pragma option push -pc
|
# pragma option push -pc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(BOOST_CLANG)
|
||||||
|
// Intel C++ on Mac defines __clang__ but doesn't support the pragma
|
||||||
# pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
# pragma clang diagnostic ignored "-Wweak-vtables"
|
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
#endif
|
#endif
|
||||||
@ -51,7 +53,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(BOOST_CLANG)
|
||||||
# pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -114,8 +114,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> result =
|
boost::shared_ptr<const int[]> result =
|
||||||
boost::allocate_shared_noinit<const
|
boost::allocate_shared_noinit<const int[]>(creator<int>(), 3);
|
||||||
int[]>(creator<int>(), 3);
|
|
||||||
BOOST_TEST(result.get() != 0);
|
BOOST_TEST(result.get() != 0);
|
||||||
BOOST_TEST(result.use_count() == 1);
|
BOOST_TEST(result.use_count() == 1);
|
||||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
@ -131,8 +130,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> result =
|
boost::shared_ptr<const int[][2]> result =
|
||||||
boost::allocate_shared_noinit<const
|
boost::allocate_shared_noinit<const int[][2]>(creator<int>(), 2);
|
||||||
int[][2]>(creator<int>(), 2);
|
|
||||||
BOOST_TEST(result.get() != 0);
|
BOOST_TEST(result.get() != 0);
|
||||||
BOOST_TEST(result.use_count() == 1);
|
BOOST_TEST(result.use_count() == 1);
|
||||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
@ -140,8 +138,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> result =
|
boost::shared_ptr<const int[2][2]> result =
|
||||||
boost::allocate_shared_noinit<const
|
boost::allocate_shared_noinit<const int[2][2]>(creator<int>());
|
||||||
int[2][2]>(creator<int>());
|
|
||||||
BOOST_TEST(result.get() != 0);
|
BOOST_TEST(result.get() != 0);
|
||||||
BOOST_TEST(result.use_count() == 1);
|
BOOST_TEST(result.use_count() == 1);
|
||||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
@ -197,8 +194,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[]> result =
|
boost::shared_ptr<const type[]> result =
|
||||||
boost::allocate_shared_noinit<const
|
boost::allocate_shared_noinit<const type[]>(creator<type>(), 3);
|
||||||
type[]>(creator<type>(), 3);
|
|
||||||
BOOST_TEST(result.get() != 0);
|
BOOST_TEST(result.get() != 0);
|
||||||
BOOST_TEST(result.use_count() == 1);
|
BOOST_TEST(result.use_count() == 1);
|
||||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
@ -210,8 +206,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[3]> result =
|
boost::shared_ptr<const type[3]> result =
|
||||||
boost::allocate_shared_noinit<const
|
boost::allocate_shared_noinit<const type[3]>(creator<type>());
|
||||||
type[3]>(creator<type>());
|
|
||||||
BOOST_TEST(result.get() != 0);
|
BOOST_TEST(result.get() != 0);
|
||||||
BOOST_TEST(result.use_count() == 1);
|
BOOST_TEST(result.use_count() == 1);
|
||||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
@ -236,8 +231,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[2][2]> result =
|
boost::shared_ptr<const type[2][2]> result =
|
||||||
boost::allocate_shared_noinit<const
|
boost::allocate_shared_noinit<const type[2][2]>(creator<type>());
|
||||||
type[2][2]>(creator<type>());
|
|
||||||
BOOST_TEST(result.get() != 0);
|
BOOST_TEST(result.get() != 0);
|
||||||
BOOST_TEST(result.use_count() == 1);
|
BOOST_TEST(result.use_count() == 1);
|
||||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
@ -66,8 +66,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> result =
|
boost::shared_ptr<const int[][2]> result =
|
||||||
boost::allocate_shared<const
|
boost::allocate_shared<const int[][2]>(creator<int>(), 2, {0, 1});
|
||||||
int[][2]>(creator<int>(), 2, {0, 1});
|
|
||||||
BOOST_TEST(result[0][0] == 0);
|
BOOST_TEST(result[0][0] == 0);
|
||||||
BOOST_TEST(result[0][1] == 1);
|
BOOST_TEST(result[0][1] == 1);
|
||||||
BOOST_TEST(result[1][0] == 0);
|
BOOST_TEST(result[1][0] == 0);
|
||||||
@ -75,8 +74,7 @@ int main()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> result =
|
boost::shared_ptr<const int[2][2]> result =
|
||||||
boost::allocate_shared<const
|
boost::allocate_shared<const int[2][2]>(creator<int>(), {0, 1});
|
||||||
int[2][2]>(creator<int>(), {0, 1});
|
|
||||||
BOOST_TEST(result[0][0] == 0);
|
BOOST_TEST(result[0][0] == 0);
|
||||||
BOOST_TEST(result[0][1] == 1);
|
BOOST_TEST(result[0][1] == 1);
|
||||||
BOOST_TEST(result[1][0] == 0);
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
Reference in New Issue
Block a user