diff --git a/include/boost/smart_ptr/allocate_shared_array.hpp b/include/boost/smart_ptr/allocate_shared_array.hpp index ae44827..f151c00 100644 --- a/include/boost/smart_ptr/allocate_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_shared_array.hpp @@ -90,6 +90,26 @@ namespace boost { d2->construct(p2, n1, p3); return shared_ptr(s1, p1); } + template + inline typename detail::sp_if_size_array::type + allocate_shared(const A& allocator, typename detail::array_list::type list) { + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; + typedef const T2 T3; + T1* p1 = 0; + T2* p2 = 0; + T3* p3 = 0; + size_t n1 = detail::array_size::size; + detail::allocate_array_helper a1(allocator, n1, &p2); + detail::array_deleter d1; + shared_ptr s1(p1, d1, a1); + detail::array_deleter* d2; + p3 = reinterpret_cast(list.begin()); + p1 = reinterpret_cast(p2); + d2 = get_deleter >(s1); + d2->construct(p2, n1, p3); + return shared_ptr(s1, p1); + } #endif } diff --git a/include/boost/smart_ptr/detail/array_traits.hpp b/include/boost/smart_ptr/detail/array_traits.hpp index d8f93ef..d80798f 100644 --- a/include/boost/smart_ptr/detail/array_traits.hpp +++ b/include/boost/smart_ptr/detail/array_traits.hpp @@ -56,6 +56,10 @@ namespace boost { struct array_list { typedef std::initializer_list type; }; + template + struct array_list { + typedef std::initializer_list type; + }; #endif } } diff --git a/include/boost/smart_ptr/make_shared_array.hpp b/include/boost/smart_ptr/make_shared_array.hpp index 10d42a5..a1a9f40 100644 --- a/include/boost/smart_ptr/make_shared_array.hpp +++ b/include/boost/smart_ptr/make_shared_array.hpp @@ -90,6 +90,26 @@ namespace boost { d2->construct(p2, n1, p3); return shared_ptr(s1, p1); } + template + inline typename detail::sp_if_size_array::type + make_shared(typename detail::array_list::type list) { + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; + typedef const T2 T3; + T1* p1 = 0; + T2* p2 = 0; + T3* p3 = 0; + size_t n1 = detail::array_size::size; + detail::make_array_helper a1(n1, &p2); + detail::array_deleter d1; + shared_ptr s1(p1, d1, a1); + detail::array_deleter* d2; + p3 = reinterpret_cast(list.begin()); + p1 = reinterpret_cast(p2); + d2 = get_deleter >(s1); + d2->construct(p2, n1, p3); + return shared_ptr(s1, p1); + } #endif template inline typename detail::sp_if_array::type diff --git a/make_shared_array.html b/make_shared_array.html index 01bf71b..5553f41 100644 --- a/make_shared_array.html +++ b/make_shared_array.html @@ -50,9 +50,15 @@ #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) template<typename T, typename... Args> shared_ptr<T[]> make_shared(std::initializer_list<T> list); + + template<typename T, typename... Args> + shared_ptr<T[N]> make_shared(std::initializer_list<T> list); template<typename T, typename A, typename... Args> shared_ptr<T[]> allocate_shared(const A& allocator, std::initializer_list<T> list); + + template<typename T, typename A, typename... Args> + shared_ptr<T[N]> allocate_shared(const A& allocator, std::initializer_list<T> list); #endif template<typename T> diff --git a/test/allocate_shared_array_create_test.cpp b/test/allocate_shared_array_create_test.cpp index 9959838..3c18844 100644 --- a/test/allocate_shared_array_create_test.cpp +++ b/test/allocate_shared_array_create_test.cpp @@ -118,6 +118,13 @@ int main() { BOOST_TEST(a1[2] == 2); BOOST_TEST(a1[3] == 3); } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } #endif return boost::report_errors(); } diff --git a/test/allocate_shared_arrays_create_test.cpp b/test/allocate_shared_arrays_create_test.cpp index 08226e0..d88a428 100644 --- a/test/allocate_shared_arrays_create_test.cpp +++ b/test/allocate_shared_arrays_create_test.cpp @@ -18,6 +18,13 @@ int main() { BOOST_TEST(a1[1][0] == 2); BOOST_TEST(a1[1][1] == 3); } + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { {0, 1}, {2, 3} }); + BOOST_TEST(a1[0][0] == 0); + BOOST_TEST(a1[0][1] == 1); + BOOST_TEST(a1[1][0] == 2); + BOOST_TEST(a1[1][1] == 3); + } #endif return boost::report_errors(); } diff --git a/test/make_shared_array_create_test.cpp b/test/make_shared_array_create_test.cpp index cc47dd6..1c6ca08 100644 --- a/test/make_shared_array_create_test.cpp +++ b/test/make_shared_array_create_test.cpp @@ -118,6 +118,13 @@ int main() { BOOST_TEST(a1[2] == 2); BOOST_TEST(a1[3] == 3); } + { + boost::shared_ptr a1 = boost::make_shared({ 0, 1, 2, 3 }); + BOOST_TEST(a1[0] == 0); + BOOST_TEST(a1[1] == 1); + BOOST_TEST(a1[2] == 2); + BOOST_TEST(a1[3] == 3); + } #endif return boost::report_errors(); } diff --git a/test/make_shared_arrays_create_test.cpp b/test/make_shared_arrays_create_test.cpp index 08c1e4a..5e773a5 100644 --- a/test/make_shared_arrays_create_test.cpp +++ b/test/make_shared_arrays_create_test.cpp @@ -18,6 +18,13 @@ int main() { BOOST_TEST(a1[1][0] == 2); BOOST_TEST(a1[1][1] == 3); } + { + boost::shared_ptr a1 = boost::make_shared({ {0, 1}, {2, 3} }); + BOOST_TEST(a1[0][0] == 0); + BOOST_TEST(a1[0][1] == 1); + BOOST_TEST(a1[1][0] == 2); + BOOST_TEST(a1[1][1] == 3); + } #endif return boost::report_errors(); }