Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81261 - in trunk: boost/smart_ptr boost/smart_ptr/detail libs/smart_ptr/test
From: glenfe_at_[hidden]
Date: 2012-11-09 11:06:49


Author: glenfe
Date: 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
New Revision: 81261
URL: http://svn.boost.org/trac/boost/changeset/81261

Log:
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.
Added:
   trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp (contents, props changed)
   trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/smart_ptr/allocate_shared_array.hpp | 12 ++++++------
   trunk/boost/smart_ptr/detail/array_traits.hpp | 26 ++++++++++++++------------
   trunk/boost/smart_ptr/detail/sp_if_array.hpp | 6 ++++--
   trunk/boost/smart_ptr/make_shared_array.hpp | 16 ++++++++--------
   trunk/libs/smart_ptr/test/Jamfile.v2 | 2 ++
   5 files changed, 34 insertions(+), 28 deletions(-)

Modified: trunk/boost/smart_ptr/allocate_shared_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/allocate_shared_array.hpp (original)
+++ trunk/boost/smart_ptr/allocate_shared_array.hpp 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -19,8 +19,8 @@
     template<typename T, typename A>
     inline typename detail::sp_if_array<T>::type
     allocate_shared(const A& allocator, size_t size) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
         size_t n1 = size * detail::array_size<T1>::size;
@@ -37,8 +37,8 @@
     template<typename T, typename A, typename... Args>
     inline typename detail::sp_if_array<T>::type
     allocate_shared(const A& allocator, size_t size, Args&&... args) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
         size_t n1 = size * detail::array_size<T1>::size;
@@ -56,8 +56,8 @@
     template<typename T, typename A>
     inline typename detail::sp_if_array<T>::type
     allocate_shared(const A& allocator, typename detail::array_list<T>::type list) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         typedef const T2 T3;
         T1* p1 = 0;
         T2* p2 = 0;

Modified: trunk/boost/smart_ptr/detail/array_traits.hpp
==============================================================================
--- trunk/boost/smart_ptr/detail/array_traits.hpp (original)
+++ trunk/boost/smart_ptr/detail/array_traits.hpp 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -13,44 +13,46 @@
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
 #include <initializer_list>
 #endif
+#include <cstddef>
 
 namespace boost {
     namespace detail {
         template<typename T>
- struct array_type {
+ struct array_base {
             typedef typename boost::remove_cv<T>::type type;
         };
-#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
- template<typename T, size_t N>
- struct array_type<T[N]> {
- typedef typename array_type<T>::type type;
+ template<typename T, std::size_t N>
+ struct array_base<T[N]> {
+ typedef typename array_base<T>::type type;
         };
-#endif
         template<typename T>
         struct array_size {
             enum {
                 size = 1
             };
         };
-#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
- template<typename T, size_t N>
+ template<typename T, std::size_t N>
         struct array_size<T[N]> {
             enum {
                 size = N * array_size<T>::size
             };
         };
-#endif
-#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
         template<typename T>
+ struct array_inner {
+ };
+ template<typename T>
+ struct array_inner<T[]> {
+ typedef T type;
+ };
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ template<typename T>
         struct array_list {
         };
-#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
         template<typename T>
         struct array_list<T[]> {
             typedef std::initializer_list<T> type;
         };
 #endif
-#endif
     }
 }
 

Modified: trunk/boost/smart_ptr/detail/sp_if_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/detail/sp_if_array.hpp (original)
+++ trunk/boost/smart_ptr/detail/sp_if_array.hpp 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -16,12 +16,14 @@
         template<typename T>
         struct sp_if_array {
         };
-#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
         template<typename T>
         struct sp_if_array<T[]> {
             typedef boost::shared_ptr<T[]> type;
         };
-#endif
+ template<typename T, size_t N>
+ struct sp_if_array<T[N]> {
+ typedef boost::shared_ptr<T[N]> type;
+ };
     }
 }
 

Modified: trunk/boost/smart_ptr/make_shared_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/make_shared_array.hpp (original)
+++ trunk/boost/smart_ptr/make_shared_array.hpp 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -19,8 +19,8 @@
     template<typename T>
     inline typename detail::sp_if_array<T>::type
     make_shared(std::size_t size) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
         size_t n1 = size * detail::array_size<T1>::size;
@@ -37,8 +37,8 @@
     template<typename T, typename... Args>
     inline typename detail::sp_if_array<T>::type
     make_shared(std::size_t size, Args&&... args) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
         size_t n1 = size * detail::array_size<T1>::size;
@@ -56,8 +56,8 @@
     template<typename T>
     inline typename detail::sp_if_array<T>::type
     make_shared(typename detail::array_list<T>::type list) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         typedef const T2 T3;
         T1* p1 = 0;
         T2* p2 = 0;
@@ -77,8 +77,8 @@
     template<typename T>
     inline typename detail::sp_if_array<T>::type
     make_shared_noinit(std::size_t size) {
- typedef typename shared_ptr<T>::element_type T1;
- typedef typename detail::array_type<T1>::type T2;
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
         size_t n1 = size * detail::array_size<T1>::size;

Modified: trunk/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- trunk/libs/smart_ptr/test/Jamfile.v2 (original)
+++ trunk/libs/smart_ptr/test/Jamfile.v2 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -134,12 +134,14 @@
           [ 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 ]
         ;

Added: trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -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 <boost/detail/lightweight_test.hpp>
+#include <boost/smart_ptr/allocate_shared_array.hpp>
+
+int main() {
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ {
+ boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), { {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();
+}

Added: trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp 2012-11-09 11:06:48 EST (Fri, 09 Nov 2012)
@@ -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 <boost/detail/lightweight_test.hpp>
+#include <boost/smart_ptr/make_shared_array.hpp>
+
+int main() {
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ {
+ boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>({ {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();
+}


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