From ffa3327817fce77ce0cd73dde0be69431d6c597d Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Fri, 9 Nov 2012 16:06:48 +0000 Subject: [PATCH] For allocate_shared and make_shared: Separate test case that g++ does support yet. Remove macros testing for no partial specialization in traits. Add additional traits. [SVN r81261] --- .../boost/smart_ptr/allocate_shared_array.hpp | 12 ++++----- .../boost/smart_ptr/detail/array_traits.hpp | 26 ++++++++++--------- .../boost/smart_ptr/detail/sp_if_array.hpp | 6 +++-- include/boost/smart_ptr/make_shared_array.hpp | 16 ++++++------ test/Jamfile.v2 | 2 ++ test/allocate_shared_arrays_create_test.cpp | 23 ++++++++++++++++ test/make_shared_arrays_create_test.cpp | 23 ++++++++++++++++ 7 files changed, 80 insertions(+), 28 deletions(-) create mode 100644 test/allocate_shared_arrays_create_test.cpp create mode 100644 test/make_shared_arrays_create_test.cpp diff --git a/include/boost/smart_ptr/allocate_shared_array.hpp b/include/boost/smart_ptr/allocate_shared_array.hpp index 8a70098..d0123a6 100644 --- a/include/boost/smart_ptr/allocate_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_shared_array.hpp @@ -19,8 +19,8 @@ namespace boost { template inline typename detail::sp_if_array::type allocate_shared(const A& allocator, size_t size) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; T1* p1 = 0; T2* p2 = 0; size_t n1 = size * detail::array_size::size; @@ -37,8 +37,8 @@ namespace boost { template inline typename detail::sp_if_array::type allocate_shared(const A& allocator, size_t size, Args&&... args) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; T1* p1 = 0; T2* p2 = 0; size_t n1 = size * detail::array_size::size; @@ -56,8 +56,8 @@ namespace boost { template inline typename detail::sp_if_array::type allocate_shared(const A& allocator, typename detail::array_list::type list) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; typedef const T2 T3; T1* p1 = 0; T2* p2 = 0; diff --git a/include/boost/smart_ptr/detail/array_traits.hpp b/include/boost/smart_ptr/detail/array_traits.hpp index ba22f61..b95a598 100644 --- a/include/boost/smart_ptr/detail/array_traits.hpp +++ b/include/boost/smart_ptr/detail/array_traits.hpp @@ -13,43 +13,45 @@ #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) #include #endif +#include namespace boost { namespace detail { template - struct array_type { + struct array_base { typedef typename boost::remove_cv::type type; }; -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - template - struct array_type { - typedef typename array_type::type type; + template + struct array_base { + typedef typename array_base::type type; }; -#endif template struct array_size { enum { size = 1 }; }; -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - template + template struct array_size { enum { size = N * array_size::size }; }; -#endif -#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) template + struct array_inner { + }; + template + struct array_inner { + typedef T type; + }; +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + template struct array_list { }; -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) template struct array_list { typedef std::initializer_list type; }; -#endif #endif } } diff --git a/include/boost/smart_ptr/detail/sp_if_array.hpp b/include/boost/smart_ptr/detail/sp_if_array.hpp index b907294..4a838fc 100644 --- a/include/boost/smart_ptr/detail/sp_if_array.hpp +++ b/include/boost/smart_ptr/detail/sp_if_array.hpp @@ -16,12 +16,14 @@ namespace boost { template struct sp_if_array { }; -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) template struct sp_if_array { typedef boost::shared_ptr type; }; -#endif + template + struct sp_if_array { + typedef boost::shared_ptr type; + }; } } diff --git a/include/boost/smart_ptr/make_shared_array.hpp b/include/boost/smart_ptr/make_shared_array.hpp index 9c30e94..50a78fd 100644 --- a/include/boost/smart_ptr/make_shared_array.hpp +++ b/include/boost/smart_ptr/make_shared_array.hpp @@ -19,8 +19,8 @@ namespace boost { template inline typename detail::sp_if_array::type make_shared(std::size_t size) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; T1* p1 = 0; T2* p2 = 0; size_t n1 = size * detail::array_size::size; @@ -37,8 +37,8 @@ namespace boost { template inline typename detail::sp_if_array::type make_shared(std::size_t size, Args&&... args) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; T1* p1 = 0; T2* p2 = 0; size_t n1 = size * detail::array_size::size; @@ -56,8 +56,8 @@ namespace boost { template inline typename detail::sp_if_array::type make_shared(typename detail::array_list::type list) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; typedef const T2 T3; T1* p1 = 0; T2* p2 = 0; @@ -77,8 +77,8 @@ namespace boost { template inline typename detail::sp_if_array::type make_shared_noinit(std::size_t size) { - typedef typename shared_ptr::element_type T1; - typedef typename detail::array_type::type T2; + typedef typename detail::array_inner::type T1; + typedef typename detail::array_base::type T2; T1* p1 = 0; T2* p2 = 0; size_t n1 = size * detail::array_size::size; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f445193..d8fbe2a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -134,12 +134,14 @@ import testing ; [ run make_shared_array_test.cpp ] [ run make_shared_arrays_test.cpp ] [ run make_shared_array_create_test.cpp ] + [ run make_shared_arrays_create_test.cpp ] [ run make_shared_array_throws_test.cpp ] [ run make_shared_array_esft_test.cpp ] [ run make_shared_array_args_test.cpp ] [ run allocate_shared_array_test.cpp ] [ run allocate_shared_arrays_test.cpp ] [ run allocate_shared_array_create_test.cpp ] + [ run allocate_shared_arrays_create_test.cpp ] [ run allocate_shared_array_throws_test.cpp ] [ run allocate_shared_array_esft_test.cpp ] ; diff --git a/test/allocate_shared_arrays_create_test.cpp b/test/allocate_shared_arrays_create_test.cpp new file mode 100644 index 0000000..08226e0 --- /dev/null +++ b/test/allocate_shared_arrays_create_test.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012 Glen Joseph Fernandes + * glenfe at live dot com + * + * Distributed under the Boost Software License, + * Version 1.0. (See accompanying file LICENSE_1_0.txt + * or copy at http://boost.org/LICENSE_1_0.txt) + */ +#include +#include + +int main() { +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + { + 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_arrays_create_test.cpp b/test/make_shared_arrays_create_test.cpp new file mode 100644 index 0000000..08c1e4a --- /dev/null +++ b/test/make_shared_arrays_create_test.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012 Glen Joseph Fernandes + * glenfe at live dot com + * + * Distributed under the Boost Software License, + * Version 1.0. (See accompanying file LICENSE_1_0.txt + * or copy at http://boost.org/LICENSE_1_0.txt) + */ +#include +#include + +int main() { +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + { + 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(); +}