forked from boostorg/smart_ptr
Use const T (&)[N] for fixed size arrays instead of std::initializer<T> in overloads of make_shared and allocate_shared for arrays.
[SVN r81641]
This commit is contained in:
@ -60,9 +60,11 @@ namespace boost {
|
||||
allocate_shared(const A& allocator, Args&&... args) {
|
||||
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;
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
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);
|
||||
@ -97,21 +99,21 @@ namespace boost {
|
||||
}
|
||||
template<typename T, typename A>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
allocate_shared(const A& allocator,
|
||||
std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
|
||||
allocate_shared(const A& allocator, const T& list) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == boost::detail::array_size<T>::size);
|
||||
enum {
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
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;
|
||||
p3 = reinterpret_cast<T3*>(list.begin());
|
||||
p3 = reinterpret_cast<T3*>(list);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
|
||||
d2->construct_list(p2, p3);
|
||||
@ -124,10 +126,12 @@ namespace boost {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
enum {
|
||||
M = boost::detail::array_total<T1>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
enum { M = boost::detail::array_total<T1>::size };
|
||||
std::size_t n1 = M * list.size();
|
||||
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
|
||||
boost::detail::array_deleter<T2[]> d1;
|
||||
@ -142,21 +146,22 @@ namespace boost {
|
||||
template<typename T, typename A>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
allocate_shared(const A& allocator,
|
||||
std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
|
||||
const typename boost::detail::array_inner<T>::type& list) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == boost::detail::array_size<T1>::size);
|
||||
enum {
|
||||
M = boost::detail::array_total<T1>::size,
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
enum { M = boost::detail::array_total<T1>::size };
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
T3* p3 = 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;
|
||||
p3 = reinterpret_cast<T3*>(list.begin());
|
||||
p3 = reinterpret_cast<T3*>(list);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
|
||||
d2->construct_list(p2, p3, M);
|
||||
|
@ -22,8 +22,7 @@ namespace boost {
|
||||
typedef typename array_base<T>::type type;
|
||||
};
|
||||
template<typename T>
|
||||
struct array_size {
|
||||
};
|
||||
struct array_size;
|
||||
template<typename T, std::size_t N>
|
||||
struct array_size<T[N]> {
|
||||
enum {
|
||||
@ -43,8 +42,7 @@ namespace boost {
|
||||
};
|
||||
};
|
||||
template<typename T>
|
||||
struct array_inner {
|
||||
};
|
||||
struct array_inner;
|
||||
template<typename T>
|
||||
struct array_inner<T[]> {
|
||||
typedef T type;
|
||||
@ -54,16 +52,11 @@ namespace boost {
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T>
|
||||
struct arrays_inner {
|
||||
};
|
||||
struct arrays_inner;
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,9 +60,11 @@ namespace boost {
|
||||
make_shared(Args&&... args) {
|
||||
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;
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
boost::detail::make_array_helper<T2[N]> a1(&p2);
|
||||
boost::detail::array_deleter<T2[N]> d1;
|
||||
boost::shared_ptr<T> s1(p1, d1, a1);
|
||||
@ -93,23 +95,24 @@ namespace boost {
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
|
||||
d2->construct_list(p2, n1, p3);
|
||||
return boost::shared_ptr<T>(s1, p1);
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
make_shared(std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
|
||||
make_shared(const T& list) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == boost::detail::array_size<T>::size);
|
||||
enum {
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
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;
|
||||
p3 = reinterpret_cast<T3*>(list.begin());
|
||||
p3 = reinterpret_cast<T3*>(list);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
|
||||
d2->construct_list(p2, p3);
|
||||
@ -122,10 +125,12 @@ namespace boost {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
enum {
|
||||
M = boost::detail::array_total<T1>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
enum { M = boost::detail::array_total<T1>::size };
|
||||
std::size_t n1 = M * size;
|
||||
boost::detail::make_array_helper<T2[]> a1(n1, &p2);
|
||||
boost::detail::array_deleter<T2[]> d1;
|
||||
@ -139,21 +144,22 @@ namespace boost {
|
||||
}
|
||||
template<typename T>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
make_shared(std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
|
||||
make_shared(const typename boost::detail::array_inner<T>::type& list) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
BOOST_ASSERT(list.size() == boost::detail::array_size<T1>::size);
|
||||
enum {
|
||||
M = boost::detail::array_total<T1>::size,
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = 0;
|
||||
enum { M = boost::detail::array_total<T1>::size };
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
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;
|
||||
p3 = reinterpret_cast<T3*>(list.begin());
|
||||
p3 = reinterpret_cast<T3*>(list);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
|
||||
d2->construct_list(p2, p3, M);
|
||||
@ -182,9 +188,11 @@ namespace boost {
|
||||
make_shared_noinit() {
|
||||
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;
|
||||
enum { N = boost::detail::array_total<T>::size };
|
||||
boost::detail::make_array_helper<T2[N]> a1(&p2);
|
||||
boost::detail::array_deleter<T2[N]> d1;
|
||||
boost::shared_ptr<T> s1(p1, d1, a1);
|
||||
|
@ -54,25 +54,25 @@
|
||||
shared_ptr<T[]> <a href="#functions">make_shared</a>(initializer_list<T> list);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[N]> <a href="#functions">make_shared</a>(initializer_list<T> list);
|
||||
shared_ptr<T[N]> <a href="#functions">make_shared</a>(const T (&list)[N]);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[][N]> <a href="#functions">make_shared</a>(size_t size, initializer_list<T> list);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[M][N]> <a href="#functions">make_shared</a>(initializer_list<T> list);
|
||||
shared_ptr<T[M][N]> <a href="#functions">make_shared</a>(const T (&list)[N]);
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[]> <a href="#functions">allocate_shared</a>(const A& allocator, initializer_list<T> list);
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[N]> <a href="#functions">allocate_shared</a>(const A& allocator, initializer_list<T> list);
|
||||
shared_ptr<T[N]> <a href="#functions">allocate_shared</a>(const A& allocator, const T (&list)[N]);
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[][N]> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, initializer_list<T> list);
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[M][N]> <a href="#functions">allocate_shared</a>(const A& allocator, initializer_list<T> list);
|
||||
shared_ptr<T[M][N]> <a href="#functions">allocate_shared</a>(const A& allocator, const T (&list)[N]);
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
@ -141,9 +141,9 @@ template<typename T, typename A, typename... Args>
|
||||
from the initializer list.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[N]> make_shared(initializer_list<T> list);
|
||||
shared_ptr<T[N]> make_shared(const T (&list)[N]);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[N]> allocate_shared(const A& allocator, initializer_list<T> list);</pre>
|
||||
shared_ptr<T[N]> allocate_shared(const A& allocator, const T (&list)[N]);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads of the utilities above are for a
|
||||
fixed size array.</p>
|
||||
@ -157,9 +157,9 @@ template<typename T, typename A, typename... Args>
|
||||
from the initializer list.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[M][N]> make_shared(initializer_list<T> list);
|
||||
shared_ptr<T[M][N]> make_shared(const T (&list)[N]);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[M][N]> allocate_shared(const A& allocator, initializer_list<T> list);</pre>
|
||||
shared_ptr<T[M][N]> allocate_shared(const A& allocator, const T (&list)[N]);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads of the utilities above are for a
|
||||
fixed size array.</p>
|
||||
|
@ -11,6 +11,20 @@
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), {0, 1, 2, 3});
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), {0, 1, 2, 3});
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
|
@ -12,6 +12,20 @@
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>({0, 1, 2, 3});
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>({0, 1, 2, 3});
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 2);
|
||||
BOOST_TEST(a1[3] == 3);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>({ {0, 1}, {2, 3} });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
|
Reference in New Issue
Block a user