mirror of
https://github.com/boostorg/smart_ptr.git
synced 2026-05-05 04:14:19 +02:00
Add overloads of make_shared and allocate_shared for arrays for E&& where E is typename boost::detail::array_base<T>::type
[SVN r81700]
This commit is contained in:
@@ -169,6 +169,46 @@ namespace boost {
|
||||
d2->construct_list(p2, p3, M);
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
#if defined(BOOST_HAS_RVALUE_REFS)
|
||||
template<typename T, typename A>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
allocate_shared(const A& allocator, std::size_t size,
|
||||
typename boost::detail::array_base<T>::type&& value) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
std::size_t n1 = size * boost::detail::array_total<T1>::size;
|
||||
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
|
||||
boost::detail::array_deleter<T2[]> d1(n1);
|
||||
boost::shared_ptr<T> s1(p1, d1, a1);
|
||||
boost::detail::array_deleter<T2[]>* d2;
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
|
||||
d2->construct(p2, boost::detail::sp_forward<T2>(value));
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
template<typename T, typename A>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
allocate_shared(const A& allocator,
|
||||
typename boost::detail::array_base<T>::type&& value) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
enum {
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
|
||||
boost::detail::array_deleter<T2[N]> d1;
|
||||
boost::shared_ptr<T> s1(p1, d1, a1);
|
||||
boost::detail::array_deleter<T2[N]>* d2;
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
|
||||
d2->construct(p2, boost::detail::sp_forward<T2>(value));
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,20 @@ namespace boost {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
#if defined(BOOST_HAS_RVALUE_REFS)
|
||||
void construct(T* memory, T&& value) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (object = memory; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(value);
|
||||
}
|
||||
} catch (...) {
|
||||
destroy(i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL)
|
||||
template<typename... Args>
|
||||
void construct(T* memory, Args&&... args) {
|
||||
std::size_t i = 0;
|
||||
@@ -52,6 +65,7 @@ namespace boost {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
void construct_list(T* memory, const T* list) {
|
||||
std::size_t i = 0;
|
||||
@@ -125,7 +139,20 @@ namespace boost {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
#if defined(BOOST_HAS_RVALUE_REFS)
|
||||
void construct(T* memory, T&& value) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (object = memory; i < N; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(value);
|
||||
}
|
||||
} catch (...) {
|
||||
destroy(i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL)
|
||||
template<typename... Args>
|
||||
void construct(T* memory, Args&&... args) {
|
||||
std::size_t i = 0;
|
||||
@@ -139,6 +166,7 @@ namespace boost {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
void construct_list(T* memory, const T* list) {
|
||||
std::size_t i = 0;
|
||||
|
||||
@@ -17,6 +17,10 @@ namespace boost {
|
||||
struct array_base {
|
||||
typedef typename boost::remove_cv<T>::type type;
|
||||
};
|
||||
template<typename T>
|
||||
struct array_base<T[]> {
|
||||
typedef typename array_base<T>::type type;
|
||||
};
|
||||
template<typename T, std::size_t N>
|
||||
struct array_base<T[N]> {
|
||||
typedef typename array_base<T>::type type;
|
||||
|
||||
@@ -14,15 +14,13 @@
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
struct sp_if_array {
|
||||
};
|
||||
struct sp_if_array;
|
||||
template<typename T>
|
||||
struct sp_if_array<T[]> {
|
||||
typedef boost::shared_ptr<T[]> type;
|
||||
};
|
||||
template<typename T>
|
||||
struct sp_if_size_array {
|
||||
};
|
||||
struct sp_if_size_array;
|
||||
template<typename T, std::size_t N>
|
||||
struct sp_if_size_array<T[N]> {
|
||||
typedef boost::shared_ptr<T[N]> type;
|
||||
|
||||
@@ -167,6 +167,45 @@ namespace boost {
|
||||
d2->construct_list(p2, p3, M);
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
#if defined(BOOST_HAS_RVALUE_REFS)
|
||||
template<typename T>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
make_shared(std::size_t size,
|
||||
typename boost::detail::array_base<T>::type&& value) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
std::size_t n1 = size * boost::detail::array_total<T1>::size;
|
||||
boost::detail::make_array_helper<T2[]> a1(n1, &p2);
|
||||
boost::detail::array_deleter<T2[]> d1(n1);
|
||||
boost::shared_ptr<T> s1(p1, d1, a1);
|
||||
boost::detail::array_deleter<T2[]>* d2;
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
|
||||
d2->construct(p2, boost::detail::sp_forward<T2>(value));
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
template<typename T>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
make_shared(typename boost::detail::array_base<T>::type&& value) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
enum {
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
boost::detail::make_array_helper<T2[N]> a1(&p2);
|
||||
boost::detail::array_deleter<T2[N]> d1;
|
||||
boost::shared_ptr<T> s1(p1, d1, a1);
|
||||
boost::detail::array_deleter<T2[N]>* d2;
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
|
||||
d2->construct(p2, boost::detail::sp_forward<T2>(value));
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
template<typename T>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
|
||||
Reference in New Issue
Block a user