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]
This commit is contained in:
Glen Fernandes
2012-11-09 16:06:48 +00:00
parent 999c284109
commit ffa3327817
7 changed files with 80 additions and 28 deletions

View File

@ -19,8 +19,8 @@ namespace boost {
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 @@ namespace boost {
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 @@ namespace boost {
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;

View File

@ -13,43 +13,45 @@
#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
}
}

View File

@ -16,12 +16,14 @@ namespace boost {
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;
};
}
}

View File

@ -19,8 +19,8 @@ namespace boost {
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 @@ namespace boost {
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 @@ namespace boost {
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 @@ namespace boost {
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;

View File

@ -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 ]
;

View File

@ -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();
}

View File

@ -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();
}