mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-11-20 17:29:48 +01:00
Add additional overload for allocate_shared and make_shared array forms that take initializer list of T for the array types T[M][N]
[SVN r81341]
This commit is contained in:
@@ -98,10 +98,10 @@ namespace boost {
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
allocate_shared(const A& allocator,
|
||||
std::initializer_list<typename detail::array_inner<T>::type> list) {
|
||||
BOOST_ASSERT(list.size() == detail::array_size<T>::size);
|
||||
typedef typename detail::array_inner<T>::type T1;
|
||||
typedef typename detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == detail::array_size<T>::size);
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
@@ -138,6 +138,29 @@ namespace boost {
|
||||
d2->construct_list(p2, n1, p3, n0);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
template<typename T, typename A>
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
allocate_shared(const A& allocator,
|
||||
std::initializer_list<typename detail::arrays_inner<T>::type> list) {
|
||||
typedef typename detail::array_inner<T>::type T1;
|
||||
typedef typename detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == detail::array_size<T1>::size);
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
std::size_t n0 = detail::array_total<T1>::size;
|
||||
std::size_t n1 = detail::array_total<T>::size;
|
||||
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
|
||||
detail::array_deleter<T2> d1;
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
detail::array_deleter<T2>* d2;
|
||||
p3 = reinterpret_cast<T3*>(list.begin());
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<detail::array_deleter<T2> >(s1);
|
||||
d2->construct_list(p2, n1, p3, n0);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace boost {
|
||||
template<typename T>
|
||||
struct array_size {
|
||||
};
|
||||
template<typename T, size_t N>
|
||||
template<typename T, std::size_t N>
|
||||
struct array_size<T[N]> {
|
||||
enum {
|
||||
size = N
|
||||
@@ -49,17 +49,21 @@ namespace boost {
|
||||
struct array_inner<T[]> {
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T, size_t N>
|
||||
template<typename T, std::size_t N>
|
||||
struct array_inner<T[N]> {
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T>
|
||||
struct arrays_inner {
|
||||
};
|
||||
template<typename T, size_t N>
|
||||
template<typename T, std::size_t N>
|
||||
struct arrays_inner<T[][N]> {
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T, std::size_t M, std::size_t N>
|
||||
struct arrays_inner<T[M][N]> {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,10 +96,10 @@ namespace boost {
|
||||
template<typename T>
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
make_shared(std::initializer_list<typename detail::array_inner<T>::type> list) {
|
||||
BOOST_ASSERT(list.size() == detail::array_size<T>::size);
|
||||
typedef typename detail::array_inner<T>::type T1;
|
||||
typedef typename detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == detail::array_size<T>::size);
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
@@ -136,6 +136,28 @@ namespace boost {
|
||||
d2->construct_list(p2, n1, p3, n0);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
template<typename T>
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
make_shared(std::initializer_list<typename detail::arrays_inner<T>::type> list) {
|
||||
typedef typename detail::array_inner<T>::type T1;
|
||||
typedef typename detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == detail::array_size<T1>::size);
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
std::size_t n0 = detail::array_total<T1>::size;
|
||||
std::size_t n1 = detail::array_total<T>::size;
|
||||
detail::make_array_helper<T2> a1(n1, &p2);
|
||||
detail::array_deleter<T2> d1;
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
detail::array_deleter<T2>* d2;
|
||||
p3 = reinterpret_cast<T3*>(list.begin());
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<detail::array_deleter<T2> >(s1);
|
||||
d2->construct_list(p2, n1, p3, n0);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
#endif
|
||||
template<typename T>
|
||||
inline typename detail::sp_if_array<T>::type
|
||||
|
||||
Reference in New Issue
Block a user