forked from boostorg/smart_ptr
Add overloads of allocate_shared_noinit to complement make_shared_noinit
[SVN r81858]
This commit is contained in:
@@ -209,6 +209,42 @@ namespace boost {
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
template<typename T, typename A>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
allocate_shared_noinit(const A& allocator, std::size_t size) {
|
||||
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_noinit(p2);
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
template<typename T, typename A>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
allocate_shared_noinit(const A& allocator) {
|
||||
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_noinit(p2);
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user