|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81366 - in branches/release: . boost boost/smart_ptr boost/smart_ptr/detail libs libs/smart_ptr libs/smart_ptr/test
From: pdimov_at_[hidden]
Date: 2012-11-16 09:09:21
Author: pdimov
Date: 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
New Revision: 81366
URL: http://svn.boost.org/trac/boost/changeset/81366
Log:
Merged revision(s) 81341-81342 from trunk:
Add additional overload for allocate_shared and make_shared array forms that take initializer list of T for the array types T[M][N]
........
Minor style change: Fix indentation in allocate_shared_array.hpp and make_shared_array.hpp
........
Properties modified:
branches/release/ (props changed)
branches/release/boost/ (props changed)
branches/release/libs/ (props changed)
Text files modified:
branches/release/boost/smart_ptr/allocate_shared_array.hpp | 25 ++++++++++++++++++++++++-
branches/release/boost/smart_ptr/detail/array_traits.hpp | 10 +++++++---
branches/release/boost/smart_ptr/make_shared_array.hpp | 24 +++++++++++++++++++++++-
branches/release/libs/smart_ptr/make_shared_array.html | 18 ++++++++++++++++--
branches/release/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp | 14 ++++++++++++++
branches/release/libs/smart_ptr/test/make_shared_arrays_create_test.cpp | 14 ++++++++++++++
6 files changed, 98 insertions(+), 7 deletions(-)
Modified: branches/release/boost/smart_ptr/allocate_shared_array.hpp
==============================================================================
--- branches/release/boost/smart_ptr/allocate_shared_array.hpp (original)
+++ branches/release/boost/smart_ptr/allocate_shared_array.hpp 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
@@ -98,10 +98,10 @@
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 @@
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
}
Modified: branches/release/boost/smart_ptr/detail/array_traits.hpp
==============================================================================
--- branches/release/boost/smart_ptr/detail/array_traits.hpp (original)
+++ branches/release/boost/smart_ptr/detail/array_traits.hpp 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
@@ -24,7 +24,7 @@
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 @@
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;
+ };
}
}
Modified: branches/release/boost/smart_ptr/make_shared_array.hpp
==============================================================================
--- branches/release/boost/smart_ptr/make_shared_array.hpp (original)
+++ branches/release/boost/smart_ptr/make_shared_array.hpp 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
@@ -96,10 +96,10 @@
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 @@
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
Modified: branches/release/libs/smart_ptr/make_shared_array.html
==============================================================================
--- branches/release/libs/smart_ptr/make_shared_array.html (original)
+++ branches/release/libs/smart_ptr/make_shared_array.html 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
@@ -56,7 +56,10 @@
template<typename T, typename... Args>
shared_ptr<T[][N]> make_shared(size_t size, initializer_list<T> list);
-
+
+ template<typename T, typename... Args>
+ shared_ptr<T[M][N]> make_shared(initializer_list<T> list);
+
template<typename T, typename A, typename... Args>
shared_ptr<T[]> allocate_shared(const A& allocator, initializer_list<T> list);
@@ -65,6 +68,9 @@
template<typename T, typename A, typename... Args>
shared_ptr<T[][N]> allocate_shared(const A& allocator, size_t size, initializer_list<T> list);
+
+ template<typename T, typename A, typename... Args>
+ shared_ptr<T[M][N]> allocate_shared(const A& allocator, initializer_list<T> list);
#endif
template<typename T>
@@ -117,7 +123,15 @@
constructor of <code>T</code> for each array element.</p>
</blockquote>
<h2><a name="example">Example</a></h2>
- <pre>boost::shared_ptr<int[]> array = boost::make_shared<int[]>(size);</pre>
+ <pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);
+boost::shared_ptr<point[5]> a2 = boost::make_shared<point[5]>(x, y);
+boost::shared_ptr<int[5]> a3 = boost::make_shared<int[5]>();
+boost::shared_ptr<int[]> a4 = boost::make_shared<int[]>({1, 2, 3});
+boost::shared_ptr<int[3]> a5 = boost::make_shared<int[3]>({1, 2, 3});
+boost::shared_ptr<int[][3]> a6 = boost::make_shared<int[][3]>(size, {1, 2, 3});
+boost::shared_ptr<int[5][3]> a7 = boost::make_shared<int[5][3]>({1, 2, 3});
+boost::shared_ptr<int[]> a8 = boost::make_shared_noinit<int[]>(size);
+boost::shared_ptr<int[5]> a9 = boost::make_shared_noinit<int[5]>();</pre>
<hr>
<p>$Date: 2012-10-30 10:12:25 -0800 (Tue, 30 Oct 2012) $</p>
<p><small>Copyright 2012 Glen Fernandes. Distributed under the Boost
Modified: branches/release/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp
==============================================================================
--- branches/release/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp (original)
+++ branches/release/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
@@ -26,6 +26,13 @@
BOOST_TEST(a1[1][1] == 3);
}
{
+ boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), {0, 1});
+ BOOST_TEST(a1[0][0] == 0);
+ BOOST_TEST(a1[0][1] == 1);
+ BOOST_TEST(a1[1][0] == 0);
+ BOOST_TEST(a1[1][1] == 1);
+ }
+ {
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
@@ -39,6 +46,13 @@
BOOST_TEST(a1[1][1][0] == 2);
BOOST_TEST(a1[1][1][1] == 3);
}
+ {
+ boost::shared_ptr<int[2][2][2]> a1 = boost::allocate_shared<int[2][2][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
+ BOOST_TEST(a1[0][0][0] == 0);
+ BOOST_TEST(a1[0][0][1] == 1);
+ BOOST_TEST(a1[1][1][0] == 2);
+ BOOST_TEST(a1[1][1][1] == 3);
+ }
#endif
return boost::report_errors();
}
Modified: branches/release/libs/smart_ptr/test/make_shared_arrays_create_test.cpp
==============================================================================
--- branches/release/libs/smart_ptr/test/make_shared_arrays_create_test.cpp (original)
+++ branches/release/libs/smart_ptr/test/make_shared_arrays_create_test.cpp 2012-11-16 09:09:18 EST (Fri, 16 Nov 2012)
@@ -27,6 +27,13 @@
BOOST_TEST(a1[1][1] == 3);
}
{
+ boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ 0, 1 });
+ BOOST_TEST(a1[0][0] == 0);
+ BOOST_TEST(a1[0][1] == 1);
+ BOOST_TEST(a1[1][0] == 0);
+ BOOST_TEST(a1[1][1] == 1);
+ }
+ {
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
@@ -40,6 +47,13 @@
BOOST_TEST(a1[1][1][0] == 2);
BOOST_TEST(a1[1][1][1] == 3);
}
+ {
+ boost::shared_ptr<int[2][2][2]> a1 = boost::make_shared<int[2][2][2]>({ {0, 1}, {2, 3} });
+ BOOST_TEST(a1[0][0][0] == 0);
+ BOOST_TEST(a1[0][0][1] == 1);
+ BOOST_TEST(a1[1][1][0] == 2);
+ BOOST_TEST(a1[1][1][1] == 3);
+ }
#endif
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk